【问题标题】:Can't copy JPG when using EXIF Data PHP使用 EXIF 数据 PHP 时无法复制 JPG
【发布时间】:2013-12-06 20:43:56
【问题描述】:

我已经做了大约 4 个小时了。我已经尝试了几件事,我将在提问后解释。

我有来自相关 JPG 的所有这些 EXIF 数据(如下所列)

我想要做的是用新名称将 JPG 重新保存到另一个文件夹中。在去掉“GCM_TAG”之后,这个新名称应该是 $data["EXIF"]["UserComment"]。这是在拍照前在仓库扫描的条形码。

我没有收到任何错误,我没有收到任何警告,但图像永远不会出现。如果我将代码更改为没有 $barcode,然后图像会突然出现。我试过打印 $barcode,我试过检查变量的编码是什么,我试过使用 fopen()、file_put_contents() 和 copy() 都无济于事。每个都有相同的结果。该文件夹有 777 权限,我可以使用 php 添加/删除文件,并在此代码中进行了测试。任何帮助将不胜感激。

chdir("../test_import_photos");
$directory = getcwd();

echo __FILE__;
print "<br />";
print $directory;
if ($dirhandle = opendir($directory))
{
    while (false !== ($entry = readdir($dirhandle)))
    {
        if($entry == "." || $entry == "..")
        {
            //ignore, its just the folder commands
        }
        else
        {
            $data = exif_read_data($entry,"ANY_TAG",true,false);
            //print "2";
            //print "3";

            $barcode = str_replace("GCM_TAG","",$data["EXIF"]["UserComment"]);

            $filepath = "../test_import_photos_end/X" . $barcode .  ".JPG";
            copy($entry, $filepath);
        }
    }
    closedir($dirhandle);
}


Array(
    [FILE] => Array
    (
        [FileName] => RIMG0089.JPG
        [FileDateTime] => 1385421951
        [FileSize] => 2592157
        [FileType] => 2
        [MimeType] => image/jpeg
        [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, INTEROP
    )

[COMPUTED] => Array
    (
        [html] => width="4000" height="3000"
        [Height] => 3000
        [Width] => 4000
        [IsColor] => 1
        [ByteOrderMotorola] => 1
        [ApertureFNumber] => f/3.5
        [UserComment] => GCM_TAG
        [UserCommentEncoding] => UNDEFINED
        [Copyright] =>                          
        [Thumbnail.FileType] => 2
        [Thumbnail.MimeType] => image/jpeg
    )

[IFD0] => Array
    (
        [ImageDescription] => Exif_JPEG_PICTURE                                              
        [Make] => RICOH      
        [Model] => G700 SE        
        [Orientation] => 1
        [XResolution] => 72/1
        [YResolution] => 72/1
        [ResolutionUnit] => 2
        [Software] => G700SE Firmware
        [DateTime] => 2013:11:25 02:53:04
        [YCbCrPositioning] => 2
        [Copyright] =>                          
        [Exif_IFD_Pointer] => 552
        [UndefinedTag:0xC4A5] => PrintIM0300d   

� ��'''''''^''''''' )

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

[EXIF] => Array
    (
        [ExposureTime] => 1/30
        [FNumber] => 350/100
        [ExposureProgram] => 2
        [ISOSpeedRatings] => 320
        [ExifVersion] => 0221
        [DateTimeOriginal] => 2013:11:25 02:53:04
        [DateTimeDigitized] => 2013:11:25 02:53:04
        [ComponentsConfiguration] => 
        [CompressedBitsPerPixel] => 184/100
        [ApertureValue] => 35/100
        [BrightnessValue] => 200/100
        [ExposureBiasValue] => 0/100
        [MaxApertureValue] => 361/100
        [MeteringMode] => 5
        [LightSource] => 0
        [Flash] => 16
        [FocalLength] => 500/100
        [MakerNote] => Ricoh

Rdchp��2=:�
ioy��������r

!'$,./$"# *&+0./(+%&$%%-39N;/5��qBdddNJ��������:\�E�E “E,”,'P?�=��R�O�"�EEEEY����@R%0%0%-��������:������P)` ��jdpq�Q�����������V�������������������������������������� ������6E����������������6E��������6E���������������� ����������������������

[UserComment] => GCM_TAG11800038
        [FlashPixVersion] => 0100
        [ColorSpace] => 1
        [ExifImageWidth] => 4000
        [ExifImageLength] => 3000
        [InteroperabilityOffset] => 1732
        [ExposureMode] => 0
        [WhiteBalance] => 0
        [SceneCaptureType] => 0
        [Sharpness] => 0
    )

[INTEROP] => Array
    (
        [InterOperabilityIndex] => R98
        [InterOperabilityVersion] => 0100
    )

)

【问题讨论】:

  • 保存后的文件mime类型是什么?
  • 预存和后存是图片/jpeg
  • 在你调用 exif_read_data 之后把这个 unset($data["EXIF"]["MakerNote"]); 我不能复制这个错误,因为我没有这个 exif 数据的图片。还回显 $barcode 长度以查看是否有二进制字符变得非法可用作文件名的一部分。
  • 嘿,这绝对是二进制字符,我在离开办公室之前就弄清楚了。如果您想要信用,请随时写下答案,我很乐意将其标记为已批准。否则我会写一个回复,详细说明我是如何找到解决方案的

标签: php jpeg exif


【解决方案1】:

正如我所见,文件名有错误(二进制数据可能会损坏数组()),而 copy() 只会抛出 E_WARNING 消息,必须将其添加到 error_reporting(E_ALL);或错误报告(E_WARNING);去看看。

【讨论】:

    猜你喜欢
    • 2011-04-06
    • 2012-04-17
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多