Reputation: 4196
I have a PHP photo sharing application in which user-uploaded images are resized into various thumb formats using ImageMagick.
As a seemingly "smart" way to save on file size, I am stripping exif info from these thumbs as follow:
$imagick = new Imagick($image);
$imagick->stripImage();
$imagick->writeImage($image);
This works. It does remove the EXIF info, where a thumbs of 30KB saves 12KB and becomes 18KB. A significant saving when showing many of such thumbs on a single page.
The problem however is that it works a little too well. The resulting images seem to lose a lot of color information and look "flat" compared to their non-stripped versions.
Based on my research so far, my theory is that one or both of the following is true:
Regardless of the cause of the problem, I'm looking for a way to remove EXIF information in such a way that it does not affect the image quality or color itself.
Is this even possible?
Update:
Based on Gerald Schneider's answer, I tried enforcing the quality setting to 100% prior to "stripping" the image:
$imagick = new Imagick($image);
$imagick->setCompression(imagick::COMPRESSION_JPEG);
$imagick->setCompressionQuality(100);
$imagick->stripImage();
$imagick->writeImage($image);
Unfortunately, the problem remains. Below is example output where despite setting the quality to 100%, images are still flattened.
Upvotes: 23
Views: 20339
Reputation: 1077
GIMP (another opensource image editor) also allows to remove EXIF, IPTC, XMP, thumbnail, ICC (color profile), etc meta data without loosing image/picture quality.
After opening the image in GIMP, Choose "Export" / "Export As" etc option, then select/unselect what meta data you want to remove/keep.
To keep original image quality you must select (tick mark) the option "Use quality settings from original image", which is shown under the "Quality" sliding-bar in top.
I usually like to keep ICC (save color profile meta data) option selected, to keep good color quality, with a colored photo.
Other options (Save EXIF, Save IPTC, Save XMP, Save thumbnail, etc) i usually unselect.
More info: here.
Upvotes: -3
Reputation: 5193
Consider keeping the ICC profile (which causes richer colors) while removing all other EXIF data:
In PHP + imagick:
$profiles = $img->getImageProfiles("icc", true);
$img->stripImage();
if(!empty($profiles))
$img->profileImage("icc", $profiles['icc']);
(Important note: using the ImageMagick 3.1.0 beta, the result I got from getImageProfiles()
was slightly different from the documentation. I'd advise playing around with the parameters until you get an associative array with the actual profile(s).)
For command line ImageMagick:
convert image.jpg profile.icm
convert image.jpg -strip -profile profile.icm output.jpg
Images will get recompressed of course if you use ImageMagick, but at least colors stay intact.
Hope this helps.
Upvotes: 32
Reputation: 4584
Having made similar changes to MIME types in file headers that were incorrectly stored, I'd suggest you verify the length of the EXIF data via the standard tools, and then "Zero" the data manually using multibyte string functions.
EXIF can only be a maximum of 64KB in a JPEG file, however I'm not positive if it's exacly 64KB, so I would begin with this.
Upvotes: 1