使用 PHP 从 JPG 中删除 EXIF 数据

2022-08-30 16:22:40

有没有办法使用PHP从JPG中删除EXIF数据?我听说过PEL,但我希望有一种更简单的方法。我正在上传将在线显示的图像,并希望删除EXIF数据。

谢谢!

编辑:我不/不能安装ImageMagick。


答案 1

用于在使用其他名称保存的新图像中重新创建图像的图形部分。gd

请参阅 PHP gd


编辑 2017

使用新的 Imagick 功能。

打开图像:

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

请务必在映像中保留任何 ICC 配置文件

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

然后剥离图像,并将配置文件放回(如果有)

    $img->stripImage();

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

来自这个PHP页面,请参阅Max Eremin在页面下方的评论。


答案 2

使用ImageMagick在PHP中执行此操作的快速方法(假设您已经安装并启用了它)。

<?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";
    }   
}
?>

推荐