php 如何将 exif 数据添加到图像中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/229446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:59:34  来源:igfitidea点击:

How do I add exif data to an image?

phpimage-processingimagemagickexif

提问by ConroyP

On our site, we get a large amount of photos uploaded from various sources.

在我们的网站上,我们从各种来源上传了大量照片。

In order to keep the file sizes down, we strip all exif datafrom the source using mogrify:

为了减小文件大小,我们使用mogrify从源中删除所有exif 数据

mogrify -strip image.jpg

What we'd like to be able to do is to insert some basic exif data (Copyright Initrode, etc) back onto this new "clean" image, but I can't seem to find anything in the docs that would achieve this.

我们希望能够做的是将一些基本的 exif 数据(版权 Initrode 等)插入到这个新的“干净”图像中,但我似乎无法在文档中找到任何可以实现这一点的内容。

Has anybody any experience of doing this?

有没有人有这样做的经验?

If it can't be done through imagemagick, a PHP-based solution would be the next best thing!

如果不能通过 imagemagick 完成,那么基于 PHP 的解决方案将是下一个最好的选择!

Thanks.

谢谢。

采纳答案by Ciaran

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):

将以下内容添加到 text.txt(取自此处的 IPTC 标签格式):

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

Strip all existing exif data from the image

从图像中去除所有现有的 exif 数据

mogrify -strip image.jpg

Add the credit to your image

将功劳添加到您的图像中

mogrify -profile 8BIMTEXT:text.txt image.jpg

回答by Colin Pickard

Exiftoollooks like it would be an exact match for you.

Exiftool看起来很适合你。

I haven't tried it but I'm now tempted to go and fix all my honeymoon photos which are marked 01/01/2074 because I forgot to reset the date after the batteries died.

我还没有尝试过,但我现在很想修复所有标记为 01/01/2074 的蜜月照片,因为我忘记在电池耗尽后重置日期。

回答by mwilliams

Here's a PHP Exif Librarythat should do what you need.

这是一个PHP Exif 库可以满足您的需求。

The PHP Exif Library (PEL) lets you fully manipulate Exif (Exchangeable Image File Format) data. This is the data that digital cameras place in their images, such as the date and time, shutter speed, ISO value and so on.

Using PEL, one can fully modify the Exif data, meaning that it can be both read and written. Completely new Exif data can also be added to images. PEL is written completely in PHP and depends on nothing except a standard installation of PHP, version 5. PEL is hosted on SourceForge.

PHP Exif 库 (PEL) 可让您完全操作 Exif(可交换图像文件格式)数据。这是数码相机在其图像中放置的数据,例如日期和时间、快门速度、ISO 值等。

使用 PEL,可以完全修改 Exif 数据,这意味着它可以读取和写入。全新的 Exif 数据也可以添加到图像中。PEL 完全是用 PHP 编写的,除了标准安装的 PHP 版本 5 外,什么都不依赖。PEL 托管在 SourceForge 上。

回答by Bastiaan

on linux there is a program called jhead. It can add a minimal exif header with the command:

在 linux 上有一个名为 jhead 的程序。它可以使用以下命令添加最小的 exif 标头:

jhead -mkexif img.jpg

jhead -mkexif img.jpg

回答by PhiLho

I doubt you will gain lot of space by removing Exif information...

我怀疑您会通过删除 Exif 信息获得大量空间...

Anyway, I can be wrong, but Exif metadata belongs more to store technical (and contextual) information. For stuff like copyright, you should use IPTC instead.

无论如何,我可能是错的,但 Exif 元数据更适合存储技术(和上下文)信息。对于版权之类的东西,您应该改用 IPTC。

That's something you can do, apparently, with ImageMagick: Write IPTC Data to Jpeg with ImageMagick.

显然,使用 ImageMagick 可以做到这一点:使用 ImageMagick将 IPTC 数据写入 Jpeg

回答by Andreas Bergstr?m

You can do this directly in PHP using the PELlibrary. You would do this by simply overwriting the existing EXIF-headers,

您可以使用PEL库直接在 PHP 中执行此操作。你可以通过简单地覆盖现有的 EXIF 标头来做到这一点,

// Load image data
$data = new PelDataWindow(file_get_contents('IMAGE PATH'));

// Prepare image data
$jpeg = $file = new PelJpeg();
$jpeg->load($data);

// Create new EXIF-headers, overwriting any existing ones (when writing to disk)
$exif = new PelExif();
$jpeg->setExif($exif);
$tiff = new PelTiff();
$exif->setTiff($tiff);

// Create Ifd-data that will hold EXIF-tags
$ifd0 = new PelIfd(PelIfd::IFD0);
$tiff->setIfd($ifd0);

// Create EXIF-data for copyright
$make = new PelEntryAscii(PelTag::COPYRIGHT, '2008-2017 Conroy');
$ifd0->addEntry($make);

// Add more EXIF-data...

// Save to disk
$file->saveFile('IMAGE.jpg');

You can find a complete list of all supported EXIF-data (PelTag) in the PEL docs.

您可以在 PEL 文档 中找到所有支持的 EXIF 数据 (PelTag) 的完整列表。