Viewed   366 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.

Saturday, October 15, 2022

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);
Monday, December 19, 2022

So I think I've figured out how to get this to work. The missing piece was a call to flattenImages(). I'm not exactly sure why this worked, but it seems to be what I was looking for. Here's the code (keep in mind that $this is in the context of a member method of a class that extends Imagick):

$this->removeImage(); // gets rid of the old, unprocessed image
$rgb = clone $this;

$rgb->flattenImages(); // this is what was missing above

$rgb = $rgb->combineImages(self::CHANNEL_ALL);


Can anyone comment on why this might be? I expected flattenImages() to merge the three images into one and destroy some of the information, but it appears that it actually tells ImageMagick to process all of the contained images together whereas it was processing them independently previously.

Friday, October 14, 2022

My 2 cents: First of all, try a simpler Ajax request to get yourself used to the mechanics of the thing.

All you have to do on the PHP side is echo out some data. For example, you could have your ajax open "test.php", then have "test.php" look like this:

<?php echo "working"; ?>

Then, just alert yourRequest.responseText (the response text property) and it should say "working".

Once you've got this moving smoothly, you can modify the PHP file to make a MySQL request.

Sunday, December 4, 2022

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
Saturday, October 1, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :