php - 使用 PHP GD 嵌入 IPTC 图像数据

标签 php gd iptc

我正在尝试使用 iptcembed() 将 IPTC 数据嵌入到 JPEG 图像中,但遇到了一些麻烦。

我已经验证它在最终产品中:

// Embed the IPTC data
$content = iptcembed($data, $path);

// Verify IPTC data is in the end image
$iptc = iptcparse($content);
var_dump($iptc);

返回输入的标签。

但是,当我保存并重新加载图像时,标签不存在:

// Save the edited image
$im = imagecreatefromstring($content);
imagejpeg($im, 'phplogo-edited.jpg');
imagedestroy($im);

// Get data from the saved image
$image = getimagesize('./phplogo-edited.jpg');

// If APP13/IPTC data exists output it
if(isset($image['APP13']))
{
    $iptc = iptcparse($image['APP13']);
    print_r($iptc);
}
else
{
    // Otherwise tell us what the image *does* contain
    // SO: This is what's happening
    print_r($image);
}

那么为什么保存的图像中没有标签?

PHP 源代码是 avaliable here ,各自的输出为:

  1. Image output
  2. Data output

最佳答案

getimagesize 有一个可选的第二个参数 Imageinfo,其中包含您需要的信息。

来自手册:

This optional parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed » IPTC information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable.

所以你可以像这样使用它:

<?php
$size = getimagesize('./phplogo-edited.jpg', $info);
if(isset($info['APP13']))
{
    $iptc = iptcparse($info['APP13']);
    var_dump($iptc);
}
?>

希望这有帮助...

关于php - 使用 PHP GD 嵌入 IPTC 图像数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24456/

相关文章:

php - Apache 的 mod_php 还是 FastCGI?哪个对 Wordpress 有好处?

php - 使用 php 打开 OTF 字体 - 包括希腊字符

php - 从 quicktime(电影)文件中获取缩略图

php - 按与字符串匹配的字段排序

javascript - 如何在每次刷新时用新值增加以前的值

php - 为在 PHP 中创建的图像添加边框

coldfusion - 使用 CF8 cfimage 标签生成缩略图 - 图像元数据导致文件过大

c# - 您如何从 GPS 坐标中获取国家/州/地区/城市/州/ zip /邮政?

php - 如何使子导航不影响父浏览器历史记录?