PHP GD palette colors

sky4

New Member
In PHP GD how can you convert a truecolor image to a palette without losing any colors. With \[code\]imagetruecolortopallete\[/code\] it doesn't work. I have a function that runs through all the colors and filters them (eg. grayscale). and It doesn't retain all colors, such as this picture of a Lamborghini-Picture
6bTPe.png
This is my code\[code\]$im = imagecreatefrompng("lamborghini.png");$degrees = 0;$img = imagecreatetruecolor(imagesx($im), imagesy($im));imagecopy($img, $im, 0, 0, 0, 0, imagesx($im), imagesy($im));imagetruecolortopalette($img, true, 256);$t = imagecolorstotal($img);for ($i = 0; $i < $t; $i++) { $rgb = imagecolorsforindex($img, $i); $hsv =rgbtohsv($rgb['red'], $rgb['green'], $rgb['blue']); $h = $degrees; $s = $hsv['s']; $v = $hsv['v']; while ($h > 360) {$h -= 360;}; $nrgb = hsvtorgb($h, $s, $v); imagecolorset($img, $i, $nrgb['r'], $nrgb['g'], $nrgb['b']);}imagecopy($im, $img, 0, 0, 0, 0, imagesx($img), imagesy($img));header('Content-type: image/png');imagepng($im);imagedestroy($im);\[/code\]And it looks like this
qvdeX.png
You can see it loses colors. Is there any solution?Also I don't think it has to do with my code but how \[code\]imagetruecolortopalette\[/code\] outputs it
 
Back
Top