Remove EXIF data from JPG using PHP

前端 未结 8 726
遥遥无期
遥遥无期 2020-11-27 18:53

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 onli

相关标签:
8条回答
  • 2020-11-27 19:42

    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:

    <?php
        $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

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

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

    0 讨论(0)
  • 2020-11-27 19:49

    A fast way to do it in PHP using ImageMagick (Assuming you have it installed and enabled).

    <?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";
        }   
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题