【问题标题】:Embedding IPTC image data with PHP GD使用 PHP GD 嵌入 IPTC 图像数据
【发布时间】:2010-09-06 16:05:33
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: php gd iptc


    【解决方案1】:

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

    来自手册:

    此可选参数允许您从图像文件中提取一些扩展信息。目前,这将返回不同的 JPG APP 标记作为关联数组。一些程序使用这些 APP 标记在图像中嵌入文本信息。一种很常见的做法是在 APP13 标记中嵌入 » IPTC 信息。您可以使用iptcparse() 函数将二进制 APP13 标记解析为可读的内容。

    所以你可以这样使用它:

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

    希望这会有所帮助...

    【讨论】:

    • 糟糕,我认为 param 完全不同 - 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    • 2012-05-27
    • 2011-09-28
    相关资源
    最近更新 更多