我怎样才能提取使用PerlMagick EXIF数据?
-
19-09-2019 - |
题
我目前使用Perl Magick http://www.imagemagick.org/script /perl-magick.php ,perl的接口难懂的 http://www.imagemagick.org 一>,处理和转换,我们的网站用户上传照片。我想能够也捕获一些附连到这些图像的EXIF数据的和我已经能够找出如何使用命令行接口来难懂的用下面的命令来做到这一点:
/usr/bin/identify -format "%[EXIF:*]" image.jpg
,它返回下列的EXIF信息为特定的照片:
exif:ApertureValue=29/8
exif:ColorSpace=1
exif:CompressedBitsPerPixel=3/1
exif:CustomRendered=0
exif:DateTime=2002:10:08 19:49:52
exif:DateTimeDigitized=2002:09:29 14:03:55
exif:DateTimeOriginal=2002:09:29 14:03:55
exif:DigitalZoomRatio=1/1
exif:ExifImageLength=307
exif:ExifImageWidth=410
exif:ExifOffset=192
exif:ExifVersion=48, 50, 50, 48
exif:ExposureBiasValue=0/1
exif:ExposureMode=0
exif:ExposureTime=1/1000
exif:Flash=24
exif:FlashPixVersion=48, 49, 48, 48
exif:FNumber=7/2
exif:FocalLength=227/32
exif:FocalPlaneResolutionUnit=2
exif:FocalPlaneXResolution=235741/32
exif:FocalPlaneYResolution=286622/39
exif:Make=Canon
exif:MaxApertureValue=12742/4289
exif:MeteringMode=5
exif:Model=Canon PowerShot S30
exif:ResolutionUnit=2
exif:SceneCaptureType=0
exif:SensingMethod=2
exif:ShutterSpeedValue=319/32
exif:Software=Adobe Photoshop 7.0
exif:WhiteBalance=0
exif:XResolution=180/1
exif:YResolution=180/1
我试过100的方式,从Perl的Magick获得此相同的结果,但无法弄清楚如何通过我使用的命令行相同的参数,使其正常工作。这里有几个我已经试过变化的其中没有一个似乎已经奏效:
use Image::Magick;
my $image = Image::Magick->new;
my $exif = $image->Identify('image.jpg');
print $exif;
$image->Read('image.jpg');
$exif = $image->Get('format "%[EXIF:*]"');
print $exif;
我知道有其他的方法来提取Perl中的图像文件的EXIF数据,但由于我们已经拥有了Perl的Magick模块加载,我不想通过无需加载额外的模块,浪费更多的内存。我希望有人在那里已经在其网站上这方面的工作,并可以共享解决方案。在此先感谢您的帮助!
解决方案
> cat im.pl
use Image::Magick;
my $image = Image::Magick->new();
$image->Read('/home/rjp/2009-02-18/DSC00343.JPG');
my $a = $image->Get('format', '%[EXIF:*]'); # two arguments
my @exif = split(/[\r\n]/, $a);
print join("\n", @exif);
> perl im.pl
exif:ColorSpace=1
exif:ComponentsConfiguration=...
exif:Compression=6
exif:CustomRendered=0
exif:DateTime=2009:02:13 16:18:15
exif:DateTimeDigitized=2009:02:13 16:18:15
...
这似乎工作。
版本:ImageMagick的6.3.7 06/04/09 Q16 http://www.imagemagick.org
其他提示
我强烈建议你使用菲尔·哈维的 ExifTool 。它是全面的,有据可查的。此外,它不会将整个图像读取到内存中,并根据文档,你可以仅仅通过它传递的文件句柄打开的图像文件中获取从图像Exif信息。因此,它不应该浪费大量的内存。
编辑: @rjp展示了如何访问所有的信息,而不是单独的标签。下面是如何把数据中的哈希:
#!/usr/bin/perl
use strict;
use warnings;
use Image::Magick;
my $image = Image::Magick->new;
$image->read('test.jpg');
my %exif = map { s/\s+\z//; $_ }
map { split /=/, $_ }
split /exif:/, $image->Get('format', '%[EXIF:*]');
use Data::Dumper;
print Dumper \%exif;
不隶属于 StackOverflow