php - How to remove exif from a JPG without losing image quality? -


i have php photo sharing application in user-uploaded images resized various thumb formats using imagemagick.

as seemingly "smart" way save on file size, stripping exif info these thumbs follow:

$imagick = new imagick($image); $imagick->stripimage(); $imagick->writeimage($image); 

this works. remove exif info, thumbs of 30kb saves 12kb , becomes 18kb. significant saving when showing many of such thumbs on single page.

the problem works little well. resulting images seem lose lot of color information , "flat" compared non-stripped versions.

based on research far, theory 1 or both of following true:

  • imagick throws away essential color profile information part of stripping process
  • imagick recompresses image upon saving it, losing quality

regardless of cause of problem, i'm looking way remove exif information in such way not affect image quality or color itself.

is possible?

update:

based on gerald schneider's answer, tried enforcing quality setting 100% prior "stripping" image:

$imagick = new imagick($image); $imagick->setcompression(imagick::compression_jpeg); $imagick->setcompressionquality(100); $imagick->stripimage(); $imagick->writeimage($image); 

unfortunately, problem remains. below example output despite setting quality 100%, images still flattened.

enter image description here

consider keeping icc profile (which causes richer colors) while removing other exif data:

  1. extract icc profile
  2. strip exif data , image profile
  3. add icc profile back

in php + imagick:

$profiles = $img->getimageprofiles("icc", true);  $img->stripimage();  if(!empty($profiles))     $img->profileimage("icc", $profiles['icc']); 

(important note: using imagemagick 3.1.0 beta, result got getimageprofiles() different documentation. i'd advise playing around parameters until associative array actual profile(s).)

for command line imagemagick:

convert image.jpg profile.icm convert image.jpg -strip -profile profile.icm output.jpg 

images recompressed of course if use imagemagick, @ least colors stay intact.

hope helps.


Comments