我不相信PHP本身包含编辑JPEG文件中的EXIF数据的功能,但是有一个PEAR扩展可以读写EXIF数据.
pear channel-discover pearhub.org
pear install pearhub/PEL
更新:
似乎pearhub.org网站永远失效,但您可以从GitHub下载文件(无需安装/设置,只需包含autoload.php文件).
以下是在JPEG文件中设置版权字段的示例.从GitHub下载的文件放在一个名为pel的子目录中,但您可以将它们放在任何您喜欢的位置(只需更新require_once行).
// Make the PEL functions available
require_once 'pel/autoload.php'; // Update path if your checked out copy of PEL is elsewhere
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTag;
use lsolesen\pel\PelEntryCopyright;
/*
* Values for you to set
*/
// Path and name of file you want to edit
$input_file = "/tmp/image.jpg";
// Name of file to write output to
$output_file = "/tmp/altered.jpg";
// Copyright info to add
$copyright = "Eborbob 2015";
/*
* Do the work
*/
// Load the image into PEL
$pel = new PelJpeg($input_file);
// Get the EXIF data (See the PEL docs to understand this)
$ifd = $pel->getExif()->getTiff()->getIfd();
// Get the copyright field
$entry = $ifd->getEntry(PelTag::COPYRIGHT);
if ($entry == null)
{
// No copyright field - make a new one
$entry = new PelEntryCopyright($copyright);
$ifd->addEntry($entry);
}
else
{
// Overwrite existing field
$entry->setValue($copyright);
}
// Save the updated file
$pel->saveFile($output_file);