我目前正在使用Perl Magick http://www.imagemagick.org/script/perl-magick.php,Image Magick http://www.imagemagick.org的perl接口,来处理和转换我们网站用户上传的照片。我希望也能够捕获附加到这些图像的一些EXIF数据,并且我已经能够通过以下命令使用Image Magick的命令行界面来实现这一点:
/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模块,所以我不想因为必须加载额外的模块而浪费更多的内存。我希望有人已经在他们的网站上使用了这个方法,并且可以分享这个解决方案。提前感谢您的帮助!
发布于 2009-11-10 22:55:32
> 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
发布于 2009-11-10 22:51:10
我强烈建议您使用Phil Harvey的ExifTool。它是全面的,并且有很好的文档。此外,它不会将整个图像读取到内存中,根据文档,您只需向图像传递一个指向打开的图像文件的文件句柄,即可从图像中获取Exif信息。所以它不应该浪费太多内存。
发布于 2009-11-10 23:04:29
编辑: @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;https://stackoverflow.com/questions/1708417
复制相似问题