PHP添加网站版权信息,如何将版权和作者信息添加到用PHP创建的图像?

我不相信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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值