<?php
// Retrocompatiblidad
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));
imagedestroy($src);
$src = $dst;
return(true);
}
}
// Cierre asistente
$typeof = function() use($im)
{
echo 'typeof($im) = ' . (imageistruecolor($im) ? 'true color' : 'palette'), PHP_EOL;
};
// Crear una imagen basada en paleta
$im = imagecreate(100, 100);
$typeof();
// Convertirla a color verdadero
imagepalettetotruecolor($im);
$typeof();
// Liberar la memoria
imagedestroy($im);
?>
El resultado del ejemplo sería:
typeof($im) = palette
typeof($im) = true color