Submit Your Article Forum Rules

Results 1 to 8 of 8

Thread: Removing Exif data from images on server

  1. #1
    Banned
    Join Date
    May 2012
    Posts
    10

    Removing Exif data from images on server

    Juto asked:

    Hi, at last a person who knows a lot about exif data!
    I have a simple question, I have googled but found no simple answer. What I need is a php script that removes all exif data during image upload.
    My client takes her on photo's and get photo's from her supplier. Which means that the size of these are around 2 megs. Removing all meta data gives file sizes around 30K and of course a faster site.
    Any help is much appreciated.

    Sara
    Juto if you have imagemagik installed on the server you could try this

    <?php

    $images = glob('*.jpg');

    foreach($images as $image)
    {
    try
    {
    $img = new Imagick($image);
    $img->stripImage();
    $img->writeImage($image);
    $img->clear();
    $img->destroy();

    echo "Removed EXIF data from $image. \n";

    } catch(Exception $e) {
    echo 'Exception caught: ', $e->getMessage(), "\n";
    }
    }
    ?>
    I am not a coder so I can't explain any more on this, it's just a post I came across whilst researching other exif issues.

    Hope it helps get you on your way.

    By the way - remember to test it on some images you may not want to keep - just in case.

    The other way of doing it would be to get the client to run them through a windows program on their pc beefore upload.
    There are a few 'free' or cheap progs out there to do that.
    Last edited by pewe; 05-24-2012 at 06:29 PM.

  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    15
    Hi! Thanks a lot. I will test it as soon as I can.
    Sara

  3. #3
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,823
    I don't know what you Googled but this is the SERP I got with a simple question:


    how much room does EXIF data take in an image file?


    As for the assertion removal of EXIF data will reduce a 2 MB file to 30 KB, well, that's just not so. The data itself only occupies a small amount of space, being just text. Removing it will not be a big savings, but it will protect one's privacy.

    This is what I wrote yesterday, but after taking a closer look at the actual EXIF data of an iPhone picture, it would appear that the thumbnail file is around 8 KB. Here is the dump: (my exploding and commas)
    PHP Code:
     print_r($EXIF// the variable in which the collection was stored


    Array (
     [
    FILE] => Array (
      [
    FileName] => IMG_0635.jpg,
      [
    FileDateTime] => 1337977075,
      [
    FileSize] => 1741374,
      [
    FileType] => 2,
      [
    MimeType] => image/jpeg,
      [
    SectionsFound] => ANY_TAGIFD0THUMBNAILEXIFGPS
     

     [
    COMPUTED] => Array (
      [
    html] => width="2592" height="1936",
      [
    Height] => 1936,
      [
    Width] => 2592,
      [
    IsColor] => 1,
      [
    ByteOrderMotorola] => 1,
      [
    ApertureFNumber] => f/2.8,
      [
    Thumbnail.FileType] => 2,
      [
    Thumbnail.MimeType] => image/jpeg
     
    )
     [
    IFD0] => Array (
      [
    Make] => Apple,
      [
    Model] => iPhone 4,
      [
    Orientation] => 6,
      [
    XResolution] => 72/1,
      [
    YResolution] => 72/1,
      [
    ResolutionUnit] => 2,
      [
    Software] => 4.3.3,
      [
    DateTime] => 2011:07:17 06:51:56,
      [
    YCbCrPositioning] => 1,
      [
    Exif_IFD_Pointer] => 204,
      [
    GPS_IFD_Pointer] => 574
     

     [
    THUMBNAIL] => Array (
      [
    Compression] => 6,
      [
    XResolution] => 72/1,
      [
    YResolution] => 72/1,
      [
    ResolutionUnit] => 2,
      [
    JPEGInterchangeFormat] => 870,
      [
    JPEGInterchangeFormatLength] => 8847 
     
    )
     [
    EXIF] => Array (
      [
    ExposureTime] => 1/155,
      [
    FNumber] => 14/5,
      [
    ExposureProgram] => 2,
      [
    ISOSpeedRatings] => 80,
      [
    ExifVersion] => 0221,
      [
    DateTimeOriginal] => 2011:07:17 06:51:56,
      [
    DateTimeDigitized] => 2011:07:17 06:51:56,
      [
    ComponentsConfiguration] => [ShutterSpeedValue] => 1251/172,
      [
    ApertureValue] => 4281/1441,
      [
    MeteringMode] => 3,
      [
    Flash] => 0,
      [
    FocalLength] => 77/20,
      [
    FlashPixVersion] => 0100,
      [
    ColorSpace] => 1,
      [
    ExifImageWidth] => 2592,
      [
    ExifImageLength] => 1936,
      [
    SensingMethod] => 2,
      [
    CustomRendered] => 3,
      [
    ExposureMode] => 0,
      [
    WhiteBalance] => 0,
      [
    DigitalZoomRatio] => 323/225,
      [
    SceneCaptureType] => 
     
    )
     [
    GPS] => Array (
      [
    GPSLatitudeRef] => N,
      [
    GPSLatitude] => Array (
       [
    0] => 49/1,
       [
    1] => 1700/100,
       [
    2] => 0/
      
    )
      [
    GPSLongitudeRef] => W,
      [
    GPSLongitude] => Array (
       [
    0] => 123/1,
       [
    1] => 625/100,
       [
    2] => 0/
      
    )
      [
    GPSAltitudeRef] => [GPSAltitude] => 15136/339,
      [
    GPSTimeStamp] => Array (
       [
    0] => 13/1,
       [
    1] => 51/1,
       [
    2] => 5631/
      
    )
      [
    GPSImgDirectionRef] => T,
      [
    GPSImgDirection] => 72277/234
     


    Last edited by weegillis; 05-25-2012 at 05:19 PM. Reason: exploded array dump

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    15
    Hi weegillis and thank you for your reply. Yes, you are right about the size of exif data.
    I have used a pc application which removed all metadata, I was obviously googling with wrong keywords.
    So, I have googled a and read about striping all data. This is what I beleive can be something to work on:

    @ http://www.php.net/manual/en/imagick.thumbnailimage.php
    jarrod at jarrodchristman dot com wrote:
    "Even though thumbnailImage is meant to produce the smallest file size image possible, i found it didn't.
    I put together this code and bordering different compression settings, found it produced the smallest file size:"

    Code:
    <?php
    // Max vert or horiz resolution
    $maxsize=550;// I'd like to use 20em instead, since I am moving to a responsive grid design
    
    // create new Imagick object
    $image = new Imagick('input_image_filename_and_location');
    // Shouldn't $image->stripImage(); be here?
    // Resizes to whichever is larger, width or height
    if($image->getImageHeight() <= $image->getImageWidth())
    {
    // Resize image using the lanczos resampling algorithm based on width
    $image->resizeImage($maxsize,0,Imagick::FILTER_LANCZOS,1);
    } else {
    // Resize image using the lanczos resampling algorithm based on height
    $image->resizeImage(0,$maxsize,Imagick::FILTER_LANCZOS,1);
    }
    
    // Set to use jpeg compression 
    // Ref: http://www.php.net/manual/en/imagick.setimagecompression.php
    // and http://www.php.net/manual/en/imagick.constants.php
    $image->setImageCompression(Imagick::COMPRESSION_JPEG);
    // Set compression level (1 lowest quality, 100 highest quality)
    $image->setImageCompressionQuality(90);
    // Strip out unneeded meta data
    $image->stripImage();
    // Writes resultant image to output directory
    $image->writeImage('output_image_filename_and_location');
    // Destroys Imagick object, freeing allocated resources in the process
    $image->destroy();
    ?>
    How do I use the below method with the above?
    Obviously I need size paramaters so the image aspect ratio is preserved.

    @ http://www.php.net/manual/en/imagick.setoption.php
    When shrinking a jpg you can get more then double the performance if you use
    Code:
    <?php $image->setOption('jpeg:size', '800x532') ?>
    exchanging 800x532 to the resolution you want the final image to be.
    For instance instead of this:
    Code:
    <?php
    $image = new Imagick('foo.jpg');
    ?>
    You would use this:
    Code:
    <?php
    $image = new Imagick();
    $image->setOption('jpeg:size', '800x532');
    $image->readImage('foo.jpg');
    ?>
    Here's where the image upload's action is. Am I correct in where the snippet should be inserted?
    Code:
    <?php
    // Bof instant update    
       if ($action == 'new_product_preview') {
    // copy image only if modified
            if ($dir && !is_dir(DIR_FS_CATALOG_IMAGES . $dir)) { 
                       if (mkdir(DIR_FS_CATALOG_IMAGES . $dir)) $messageStack->add('Folder ' . $dir . ' created in '. $images_dir . '.', 'success');
                    }
    
            $products_image = new upload('products_image');
    
    //      Should my code be here? <============================
    
            $products_image->set_destination(DIR_FS_CATALOG_IMAGES . ($dir ? $dir .'/' : ''));
            if ($products_image->parse() && $products_image->save()) {
    
              $products_image_name = ($dir ? $dir . '/' : '') . $products_image->filename;
            } else {
              $products_image_name = (isset($_POST['products_previous_image']) ? $_POST['products_previous_image'] : '');
            }
    
            if (isset($_POST['instant_update']) == 'on') {
             $_POST['products_image'] = $products_image_name;
            $action = (isset($_GET['pID']) ? 'update_product' : 'insert_product');  
              }
                }
    // EOF instant update
    ?>
    Thank you so much for your help.

    Sara

  5. #5
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,823
    That is something I'll have study and learn about. Unfortunately, I don't have an answer for you today. Hopefully someone with more OOP and CMS experience can pipe in with a helpful response.

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    15
    Quote Originally Posted by weegillis View Post
    That is something I'll have study and learn about. Unfortunately, I don't have an answer for you today. Hopefully someone with more OOP and CMS experience can pipe in with a helpful response.
    Ouch... apart from where the script should go... the script itself, with my comments, does it look ok?

    Sara

    {moved from another thread}

    I'm not using oscmax... I have devloped my own fork of osC.

    {}
    Last edited by weegillis; 06-11-2012 at 08:36 PM. Reason: Moved off-topic post entry to this thread.

  7. #7
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,823
    Is this the code you're working with: osCMax? If so I would recommend looking for their documentation or FAQ. It will be more accurate than the guess I could offer.

  8. #8
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,823
    To the original question, here is a product that can remove EXIF tags on a WIndows machine. ExifCleaner. Will give it a whirl myself and see what it does. As for the CMS, it is a bit off-topic for this thread. You might want to post your question in one of the other subforums, eCommerce, perhaps. Best we stick to EXIF question in this thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •