<?php
// В целях обратной совместимости
if (!function_exists('imagepalettetotruecolor')) {
function imagepalettetotruecolor(&$src)
{
if (imageistruecolor($src)) {
return (true);
}
$dst = imagecreatetruecolor(imagesx($src), imagesy($src));
imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src));
$src = $dst;
return (true);
}
}
// Анонимное замыкание-помощник
$typeof = function () use ($im) {
echo 'typeof($im) = ' . (imageistruecolor($im) ? 'true color' : 'palette'), PHP_EOL;
};
// Создаём изображение на основе палитры
$im = imagecreate(100, 100);
$typeof();
// Преобразуем цвета изображения к истинным
imagepalettetotruecolor($im);
$typeof();
?>
Результат выполнения приведённого примера:
typeof($im) = palette
typeof($im) = true color