<?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