Last active
March 12, 2023 13:12
-
-
Save ivanhoe011/daf06192aadb21af24e2fa35ead9c360 to your computer and use it in GitHub Desktop.
Proper way to remove all metadata from an image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$img = new Imagick($img); | |
// code by Max Eremin http://php.net/manual/en/imagick.stripimage.php#120380 | |
// we need to keep the ICC profiles | |
$profiles = $img->getImageProfiles('icc', true); | |
// but remove everything else | |
$img->stripImage(); | |
// re-attach the color profiles | |
if ( ! empty($profiles)) { | |
$img->profileImage('icc', $profiles['icc']); | |
} |
In file size, or dimensions?
If you can, post a link to one of the images so that we can inspect it closer. Also post the version of your php/imagemagick as this code snippet is very old, perhaps something changed recently...
Just thought of something: This process is re-compressing the image, and the default quality is set pretty high, 92 IIRC, so that could be the reason why you're getting bigger images. It's best that you set the quality down to the actual quality of the original image or the value that you want:
$img->setImageCompressionQuality($realQuality);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dont know why, but half my images increase in size after stripping the meta data