Asked  7 Months ago    Answers:  5   Viewed   35 times

Is there any way to remove the EXIF data from a JPG using PHP? I have heard of PEL, but I'm hoping there's a simpler way. I am uploading images that will be displayed online and would like the EXIF data removed.


EDIT: I don't/can't install ImageMagick.



Use gd to recreate the graphical part of the image in a new one, that you save with another name.

See PHP gd

edit 2017

Use the new Imagick feature.

Open Image:

    $incoming_file = '/Users/John/Desktop/file_loco.jpg';
    $img = new Imagick(realpath($incoming_file));

Be sure to keep any ICC profile in the image

    $profiles = $img->getImageProfiles("icc", true);

then strip image, and put the profile back if any


    if(!empty($profiles)) {
       $img->profileImage("icc", $profiles['icc']);

Comes from this PHP page, see comment from Max Eremin down the page.

Wednesday, March 31, 2021
answered 7 Months ago

You need multi-line mode (/m), otherwise your regex won't capture across multiple lines. Also, you should escape your regex parameters with preg_quote(), otherwise you may get undesired results (for example, in $end, it has a dot, which is a regex metacharacter, when you want it to match a single period.)

$regex = "/^" . preg_quote( $start, '/') .".*?". preg_quote( $end, '/') . "/sm";
preg_replace ( $regex, $replace, $fdata);
Saturday, May 29, 2021
answered 5 Months ago

You can save a large amount of space, especially if you have a large number of images..

Add the following to text.txt (format of the IPTC tags taken from here):

2#110#Credit="My Company"
2#05#Object Name="THE_OBJECT_NAME"
2#55#Date Created="2011-02-03 12:45"
2#110#Credit="The CREDIT"
2#116#Copyright Notice="THE COPYRIGHT"
2#118#Contact="THE CONTACT"
2#120#Caption="AKA Title"

Strip all existing exif data from the image

mogrify -strip image.jpg

Add the credit to your image

mogrify -profile 8BIMTEXT:text.txt image.jpg
Wednesday, June 2, 2021
answered 5 Months ago

Edit: Version 1.5.0 (July 2017) of the Extensions to the PNG 1.2 Specification has finally added an EXIF chunk. It remains to be seen if encoders-decoders begin to support it.

Original: PNG does not embed EXIF info. It allows, however, to embed metadata "chunks" inside the image. Some of the standardized chunks correspond to a few EXIF attributes (physical dimensions, timestamp). And it's also possible to store arbitrary textual data as key=>value pairs, or to define new chunk types. So, you could in theory store any EXIF information... but, alas, in your own custom format. Some attempts to standarize have not caught up, it seems.

Thursday, June 3, 2021
answered 5 Months ago

I would lean towards ImageMagick as far as image quality goes. It seems to produce considerably sharper/higher-quality images than GD2 (at the expense of larger filesize.)

ImageMagick is also not bound by PHP's memory limit.

Monday, August 9, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :