0

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?
inf3rno
  • 24,976
  • 11
  • 115
  • 197
  • You just need a specialized PNG library or commandline tool that does not re-encode the image data. Same for JPEG. This is *not* possible with the GD library (that should answer your question already: use pngcrush). – hakre Aug 30 '13 at 11:15
  • 1
    saving as jpeg you loose quality, but file size becomes smaller, with png you do not loose quality. – ViliusL Aug 30 '13 at 11:15
  • comment are controversal :S @hakre so reencoding a png file drops image quality too? is this sure? – inf3rno Aug 30 '13 at 12:24
  • @hakre "PNG is a lossless compression format for transmitting a single bitmap image over computer networks." So if I load every image with GD and save them as PNG they won't lose quality.... – inf3rno Aug 30 '13 at 12:26
  • @inf3rno: gd will re-encode the image which is waste. also you don't have well control about image format specifics, be it PNG or JPG. – hakre Aug 30 '13 at 13:02
  • @hakre: What waste, what control about image format? Can you explain me? I don't understand... :S – inf3rno Aug 30 '13 at 21:27
  • Waste in the meaning of decoding the image data and consuming the memory of the uncompressed bitmap only to encode it again. pngcrush does not decode the image-data and it allows you to more specifically control which parts to remove. – hakre Aug 30 '13 at 21:30
  • Thanks! In my current project I can afford reencoding image data. – inf3rno Aug 31 '13 at 11:42

1 Answers1

2

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.

Paul
  • 471
  • 4
  • 10