gpt4 book ai didi

php - 如何将版权和作者信息添加到用 PHP 创建的图像中?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:38:14 24 4
gpt4 key购买 nike

有什么方法可以将版权信息添加到 PHP 创建的图像文件中?

为了更清楚,您可以使用 photoshop 向文件添加 copyright 信息,因此当您获取其 properties 时,您会看到类似以下内容:

File Properties of an Image File opened in Windows 7

我想在 php 中添加/编辑文件的详细信息。有可能吗?

编辑:

我从用户输入中获取图像,然后使用此函数调整其大小:

 function image_resize($src, $w, $h, $dst, $width, $height, $extension )
{
switch($extension){
case 'bmp': $img = imagecreatefromwbmp($src); break;
case 'gif': $img = imagecreatefromgif($src); break;
case 'jpg': $img = imagecreatefromjpeg($src); break;
case 'png': $img = imagecreatefrompng($src); break;
default : return "Unsupported picture type!";
}
$new = imagecreatetruecolor($width, $height);
// preserve transparency
if($extension == "gif" or $extension == "png"){
imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
imagealphablending($new, true);
imagesavealpha($new, false);
}
imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $w, $h);
imageinterlace($new,1);//for progressive jpeg image
switch($extension){
case 'bmp': imagewbmp($new, $dst); break;
case 'gif': imagegif($new, $dst); break;
case 'jpg': imagejpeg($new, $dst); break;
case 'png': imagepng($new, $dst); break;
}
return true;
}

最佳答案

我不认为 PHP 本身包含编辑 JPEG 文件中的 EXIF 数据的功能,但是有一个 PEAR 扩展可以读取和写入 EXIF 数据。

pear channel-discover pearhub.org
pear install pearhub/PEL

该模块的网站位于 http://lsolesen.github.io/pel/设置描述的示例位于 https://github.com/lsolesen/pel/blob/master/examples/edit-description.php

更新:

pearhub.org 网站似乎已关闭/永远消失,但您可以从 GitHub 下载文件(无需安装/设置,只需包含 autoload.php 文件)。

以下是在 JPEG 文件中设置版权字段的示例。从 GitHub 下载的文件放置在名为 pel 的子目录中,但您可以将它们放置在任何您喜欢的位置(只需更新 require_once 行)。

<?php

// 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);

关于php - 如何将版权和作者信息添加到用 PHP 创建的图像中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30800875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com