Windows显示但PHP不显示的EXIF(或其他元数据)数据 [英] EXIF (or other meta-data) data that Windows displays but PHP does not

查看:110
本文介绍了Windows显示但PHP不显示的EXIF(或其他元数据)数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working to pull some information from JPEGs supplied to my client by a photographer.

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

When examined under Windows all of the images contain data in a field called Tags:

首先要进行一些测试,我制作了以下脚本,并使用下面的代码遍历二进制文件头中的条目.

To do some testing first I made the following script and am iterating over entries in the binary file headers using the code below.

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

Sometimes I get values for ImageDescription. Often text in Copyright and Author but the Tags content never ever shows up here and it is the capture of that content the client most wants to automate.

有人可以建议我如何访问标签"字段内容吗?

Can anyone advise me as to how I can access the Tags field content?

文件的上传副本位于此处.

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

UPDATE - changed IDF0 to ANY_TAG and added 3rd arg true to exif_read_data() per Tiger-222's response. Also added print_r output at end of post

更新2 添加了请求的error_display()和ini_set()调用,还尝试了exif_read_data()第二个arg值0来代替

UPDATE 2 Added requested error_display() and ini_set() calls and also tried exif_read_data() 2nd arg of 0 in place of 'ANY_TAG' per 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";
            }
        }
    }
?>

以下是脚本为高空吊车图像转储的内容:

The following is the content dumped by the script for the whooping crane image:

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

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的耐心和帮助).

In three points (thanks to jerrygarciuh for his patience and help).

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

1) To see extra informations, just pass the third argument to true:

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

此处所述,它将强制转换为避免节之间冲突的数组.您会在IFD0.Keywords关键字下找到标签.

As explained here, it will force the conversion to an array to avoid conflicts between sections. You will find Tags under the IFD0.Keywords keyword.

2) 有一个WINXP.Keywords问题.要正确显示这些信息,只需将编码设置为UFT-8:

2) There is an issue with WINXP.Keywords. To display correctly these informations, just set the encoding to UFT-8:

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

3)感谢 iptcparse阅读Lightroom设置的其他信息.这是完整的脚本:

3) Thanks to this question from Ferdy, extra informations setted by Lightroom could be read using iptcparse. This is the full script:

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

顺便说一句,好看的图片;)

By the way, nice picture ;)

这篇关于Windows显示但PHP不显示的EXIF(或其他元数据)数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆