I had problems resizing PNG and maintaining small file sizes. The solution is found here .
However, when resizing PNG, I had problems with image quality. As far as I could see, GD uses an indexed palette with 8-bit color, which distorts text and colors, gets lost, see:
² The idea of customization, which I found here in https://stackoverflow.com/a/312960/99: ... Create a truecolor image, resize it and copy to a new image, so that the palette is determined based on the result of resampling, and the image quality is better. as you can see in the image above .
// create new image $newImageTmp = imagecreatetruecolor($newwidth,$newheight); // we create a temporary truecolor image // do the image resizing by copying from the original into $newImageTmp image imagecopyresampled($newImageTmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // create output image $newImage = imagecreate($newwidth,$newheight); // copy resized truecolor image onto index-color image imagecopy($newImage,$newImageTmp,0,0,0,0,$newwidth,$newheight); // write image to buffer and save in variable ob_start(); // stdout --> buffer imagepng($newImage,NULL,6); $newImageToSave = ob_get_contents(); // store stdout in $newImageToSave ob_end_clean(); // clear buffer // remove images from php buffer imagedestroy($src); imagedestroy($newImageTmp); imagedestroy($newImage);
Problem: None of the results is satisfactory.
I am absolutely sure that there should be a way: 1. to determine the color palette and 2. to save most of the image colors so that 3. PNG looks the same as the original and has an acceptable file size.
Now I see only JPG instead of PNG. But if you know the solution, it would be very helpful if you let me / us know.
Thanks!