Actually that is not true.
When you use for example imagecreatefromjpeg() you create a truecolor image resource (as with the other truecolor image types). If you try to get the number of colors using imagecolorstotal() you get 0 (thats what happened to me at least). Instead you must convert the trucolor resource to pallete resource. You have to do that like this:<?
$simg=createfromjpeg("somejpeg.jpg");
imagetruecolortopalette($simg, false, 256);
$colors=imagecolorstotal($simg);
?>
When you use for example imagecreatefromjpeg() you create a truecolor image resource (as with the other truecolor image types). If you try to get the number of colors using imagecolorstotal() you get 0 (thats what happened to me at least). Instead you must convert the trucolor resource to pallete resource. You have to do that like this:<?
$simg=createfromjpeg("somejpeg.jpg");
imagetruecolortopalette($simg, false, 256);
$colors=imagecolorstotal($simg);
?>
<?Header("Content-type: image/jpeg");?>
<body>
<?
$image="swallow.jpg";
$im = imagecreatefromjpeg($image);
imagetruecolortopalette($im, false, 256);
echo $image.' has '.imagecolorstotal($im).' colors in its palette';
imagedestroy($im);
?>
</body>结果总是swallow.jpg has 256 colors in its palette;2.另外,我用imagecopy(),得到的temp.jpg全都是黑色的。
$image="swallow.jpg";
$im1 = imagecreatefromjpeg($image);
$im2=imagecreate(43,39);
imagetruecolortopalette($im1, false, 256);
imagetruecolortopalette($im2, false, 256);
imagecopy($im1,$im2,1,1,1,1,40,30);
imagejpeg($im2,"temp.jpg"); 帮帮忙啊!
$image="swallow.jpg";
$im1 = imagecreatefromjpeg($image);
$im2=imagecreate(43,39);
imagetruecolortopalette($im1, false, 256);
imagetruecolortopalette($im2, false, 256);
imagecopy($im1,$im2,1,1,1,1,40,30);
imagejpeg($im2,"temp.jpg"); 2.imagecolorat()的问题:
<body>
<?
$image="swallow.jpg";
$im = imagecreatefromjpeg($image);
$cindex = imagecolorat($im,0,0);
$rgb_color=imagecolorsforindex($im,$cindex);
echo $rgb_color['red'];
echo $rgb_color['green'];
echo $rgb_color['blue'];
?>
</body>执行到“$cindex = imagecolorat($im,0,0);”时,
总是弹出内存不能为读得提示