草庐IT

php - Windows 显示但 PHP 不显示的 EXIF(或其他元数据)数据

coder 2024-01-01 原文

我正在努力从一位摄影师提供给我的客户的 JPEG 中提取一些信息。

在 Windows 下检查时,所有图像都包含名为标签的字段中的数据:

为了首先进行一些测试,我制作了以下脚本并使用以下代码迭代二进制文件头中的条目。

有时我会得到 ImageDescription 的值。通常在版权和作者中显示文本,但标签内容永远不会显示在这里,它是客户最希望自动化的内容的捕获。

谁能告诉我如何访问标签字段内容?

上传的文件副本是here .

更新 - 根据 Tiger-222 的响应,将 IDF0 更改为 ANY_TAG 并将第三个参数 true 添加到 exif_read_data()。还在帖子末尾添加了 print_r 输出

更新 2 添加了请求的 error_display() 和 ini_set() 调用,还尝试了 exif_read_data() 第 2 个参数 0 代替 'ANY_TAG' 每 https://php.net/manual/en/function.exif-read-data.php

<?php
    ini_set('display_errors', 1);
    ini_set('exif.encode_unicode', 'UTF-8');  // To see WINXP values
    error_reporting(-1);        
    $n = (intval($_GET['n'])) ? $_GET['n'] : 99;
    echo "ANI_$n.jpg:<br />\n";
    $exif = exif_read_data("ANI_$n.jpg", 'ANY_TAG', true);
    echo $exif===false ? "No header data found.<br />\n" : "Image contains the following headers:<br><br />\n";

    if ($exif) {
        foreach ($exif as $key => $section) {
            if (is_array($section)) {
                foreach ($section as $name => $val) {
                    echo "$key.$name: $val<br />\n";
                }
            } else {
                echo "$key: $section<br>\n";
            }
        }
    }
?>

鸣鹤图片脚本转储内容如下:

ANI_69.jpg:
Image contains the following headers:

FileName: ANI_69.jpg
FileDateTime: 1428255617
FileSize: 2448245
FileType: 2
MimeType: image/jpeg
SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF
COMPUTED.html: width="1798" height="2697"
COMPUTED.Height: 2697
COMPUTED.Width: 1798
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 0
COMPUTED.Copyright: Photographer name here
COMPUTED.Thumbnail.FileType: 2
COMPUTED.Thumbnail.MimeType: image/jpeg
ImageWidth: 1798
ImageLength: 2697
BitsPerSample.0: 8
BitsPerSample.1: 8
BitsPerSample.2: 8
PhotometricInterpretation: 2
Orientation: 1
SamplesPerPixel: 3
XResolution: 1000000/10000
YResolution: 1000000/10000
ResolutionUnit: 2
Software: Adobe Photoshop CS6 (Macintosh)
DateTime: 2014:12:28 19:17:36
Artist: Photographer name here
Copyright: Photographer name here
Exif_IFD_Pointer: 316
THUMBNAIL.Compression: 6
THUMBNAIL.XResolution: 72/1
THUMBNAIL.YResolution: 72/1
THUMBNAIL.ResolutionUnit: 2
THUMBNAIL.JPEGInterchangeFormat: 554
THUMBNAIL.JPEGInterchangeFormatLength: 3211
ExifVersion: 0230
DateTimeOriginal: 2014:11:03 11:14:27
DateTimeDigitized: 2014:11:03 11:14:27
SubSecTimeOriginal: 76
SubSecTimeDigitized: 76
ColorSpace: 65535
ExifImageWidth: 1798
ExifImageLength: 2697

这是来自 $exif = exif_read_data("ANI_$n.jpg", 'ANY_TAG', true);

的 $exif 转储
Array
(
    [FILE] => Array
        (
            [FileName] => ANI_69.jpg
            [FileDateTime] => 1428255617
            [FileSize] => 2448245
            [FileType] => 2
            [MimeType] => image/jpeg
            [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF
        )

    [COMPUTED] => Array
        (
            [html] => width="1798" height="2697"
            [Height] => 2697
            [Width] => 1798
            [IsColor] => 1
            [ByteOrderMotorola] => 0
            [Copyright] => Digital Roux Photography LLC
            [Thumbnail.FileType] => 2
            [Thumbnail.MimeType] => image/jpeg
        )

    [IFD0] => Array
        (
            [ImageWidth] => 1798
            [ImageLength] => 2697
            [BitsPerSample] => Array
                (
                    [0] => 8
                    [1] => 8
                    [2] => 8
                )

            [PhotometricInterpretation] => 2
            [Orientation] => 1
            [SamplesPerPixel] => 3
            [XResolution] => 1000000/10000
            [YResolution] => 1000000/10000
            [ResolutionUnit] => 2
            [Software] => Adobe Photoshop CS6 (Macintosh)
            [DateTime] => 2014:12:28 19:17:36
            [Artist] => Digital Roux Photography LLC
            [Copyright] => Digital Roux Photography LLC
            [Exif_IFD_Pointer] => 316
        )

    [THUMBNAIL] => Array
        (
            [Compression] => 6
            [XResolution] => 72/1
            [YResolution] => 72/1
            [ResolutionUnit] => 2
            [JPEGInterchangeFormat] => 554
            [JPEGInterchangeFormatLength] => 3211
        )

    [EXIF] => Array
        (
            [ExifVersion] => 0230
            [DateTimeOriginal] => 2014:11:03 11:14:27
            [DateTimeDigitized] => 2014:11:03 11:14:27
            [SubSecTimeOriginal] => 76
            [SubSecTimeDigitized] => 76
            [ColorSpace] => 65535
            [ExifImageWidth] => 1798
            [ExifImageLength] => 2697
        )

)

最佳答案

分(感谢 jerrygarciuh 的耐心和帮助)。

1) 要查看额外信息,只需将第三个参数传递给 true:

$exif = exif_read_data("ANI_$n.jpg", 'IFD0', true);

如解释here , 它将强制转换为数组以避免部分之间的冲突。您会在 IFD0.Keywords 关键字下找到标签。

2) There is an issue使用 WINXP.Keywords。要正确显示这些信息,只需将编码设置为 UFT-8:

ini_set('exif.encode_unicode', 'UTF-8');

3)感谢this question from Ferdy ,可以使用 iptcparse 读取 Lightroom 设置的额外信息.这是完整的脚本:

ini_set('exif.encode_unicode', 'UTF-8');  // To see WINXP values

// Exif informations -- limited by PHP
$exif = exif_read_data("ANI_$n.jpg", 'ANY_TAG', true);
print_r($exif);

// Additionnal informations from Lightroom
getimagesize("ANI_$n.jpg", $infos);
if ( isset($infos['APP13']) ) {
    print_r(iptcparse($infos['APP13']));
}

输出:

Array
(
    [FILE] => Array
        (
            [FileName] => ANI_69.or.jpg
            [FileDateTime] => 1431382165
            [FileSize] => 2450950
            [FileType] => 2
            [MimeType] => image/jpeg
            [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, WINXP
        )

    [COMPUTED] => Array
        (
            [html] => width="1798" height="2697"
            [Height] => 2697
            [Width] => 1798
            [IsColor] => 1
            [ByteOrderMotorola] => 1
            [Copyright] => Digital Roux Photography LLC
            [Thumbnail.FileType] => 2
            [Thumbnail.MimeType] => image/jpeg
        )

    [IFD0] => Array
        (
            [ImageWidth] => 1798
            [ImageLength] => 2697
            [BitsPerSample] => Array
                (
                    [0] => 8
                    [1] => 8
                    [2] => 8
                )

            [PhotometricInterpretation] => 2
            [ImageDescription] => Rusty Costanza / Digital Roux Photography
            [Orientation] => 1
            [SamplesPerPixel] => 3
            [XResolution] => 1000000/10000
            [YResolution] => 1000000/10000
            [ResolutionUnit] => 2
            [Software] => Adobe Photoshop CS6 (Macintosh)
            [DateTime] => 2014:12:28 19:17:36
            [Artist] => Digital Roux Photography LLC
            [Copyright] => Digital Roux Photography LLC
            [Exif_IFD_Pointer] => 2468
            [Title] => Rusty Costanza / Digital Roux Photography
            [Keywords] => whooping crane
            [UndefinedTag:0xEA1C] => �
        )

    [THUMBNAIL] => Array
        (
            [Compression] => 6
            [XResolution] => 72/1
            [YResolution] => 72/1
            [ResolutionUnit] => 2
            [JPEGInterchangeFormat] => 4894
            [JPEGInterchangeFormatLength] => 3371
        )

    [EXIF] => Array
        (
            [ExifVersion] => 0230
            [DateTimeOriginal] => 2014:11:03 11:14:27
            [DateTimeDigitized] => 2014:11:03 11:14:27
            [SubSecTimeOriginal] => 76
            [SubSecTimeDigitized] => 76
            [ColorSpace] => 65535
            [ExifImageWidth] => 1798
            [ExifImageLength] => 2697
            [UndefinedTag:0xEA1C] => �
        )

    [WINXP] => Array
        (
            [Title] => 刀甀猀琀礀 䌀漀猀琀愀渀稀愀 ⼀ 䐀椀最椀琀愀氀 刀漀甀砀 倀栀漀琀漀最爀愀瀀栀礀ഀ
            [Keywords] => 眀栀漀漀瀀椀渀最 挀爀愀渀攀
        )
)

Array
(
    [1#090] => Array
        (
            [0] => 
        )

    [2#000] => Array
        (
            [0] => 
        )

    [2#055] => Array
        (
            [0] => 20141103
        )

    [2#060] => Array
        (
            [0] => 111427+0000
        )

    [2#090] => Array
        (
            [0] => New Orleans
        )

    [2#025] => Array
        (
            [0] => whooping crane
        )

    [2#080] => Array
        (
            [0] => Digital Roux Photography LLC
        )

    [2#120] => Array
        (
            [0] => Rusty Costanza / Digital Roux Photography
        )

    [2#116] => Array
        (
            [0] => Digital Roux Photography LLC
        )

    [2#221] => Array
        (
            [0] => 0:0:0:-00001
        )

    [2#062] => Array
        (
            [0] => 20141103
        )
)

顺便说一句,漂亮的照片;)

关于php - Windows 显示但 PHP 不显示的 EXIF(或其他元数据)数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30177313/

有关php - Windows 显示但 PHP 不显示的 EXIF(或其他元数据)数据的更多相关文章

  1. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  2. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  3. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  4. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

  5. ruby-on-rails - link_to 不显示任何 rails - 2

    我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article

  6. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  7. ruby - Ruby 有 `Pair` 数据类型吗? - 2

    有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳

  8. ruby - 在 Windows 机器上使用 Ruby 进行开发是否会适得其反? - 2

    这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby​​-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub

  9. ruby - 我如何添加二进制数据来遏制 POST - 2

    我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_

  10. 世界前沿3D开发引擎HOOPS全面讲解——集3D数据读取、3D图形渲染、3D数据发布于一体的全新3D应用开发工具 - 2

    无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD

随机推荐