Php - clear PNG metadata but keep similar quality

2019-08-22 04:49发布

问题:

I want to convert every uploaded image to png. I think gd is a good approach for that, because it drops the metadata of the images, and does not try to parse it. I read that ImageMagick maybe has malware vulnerability on some linux servers...

I have 2 questions:

  1. Does gd drop the PNG metadata too if the original file was PNG, or should I use pngcrush after converting?
  2. Do I have the same quality loss as by saving JPEG files, or is the PNG format much better?

回答1:

If you would open the png in PHP, copy it to a new resource, then save it at full quality (in PNG, JPEG will lose quality) it will do what you want.