如何使用PerlMagick提取EXIF数据? [英] How can I extract EXIF data using PerlMagick?

查看:124
本文介绍了如何使用PerlMagick提取EXIF数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Perl Magick http://www.imagemagick.org/script /perl-magick.php ,Image Magick的perl界面 http://www.imagemagick.org ,处理&转换我们网站用户上传的照片。我希望能够捕获附加到这些图像的一些EXIF数据,并且我已经能够使用命令行界面使用以下命令找出如何执行此操作:

I'm currently using Perl Magick http://www.imagemagick.org/script/perl-magick.php, the perl interface to Image Magick http://www.imagemagick.org, to process & convert photos that our site users upload. I'd like to be able to also capture some of the EXIF data attached to these images and I have been able to figure out how to do this using the command line interface to Image Magick with the following command:

/usr/bin/identify -format "%[EXIF:*]" image.jpg

返回特定照片的以下EXIF信息:

Which returns the following EXIF information for a particular photo:

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获得相同的结果但无法弄清楚如何通过我在命令行上使用的相同参数使其正常工作。以下是我尝试过的几种变体,但似乎没有一种变化:

I've tried about 100 ways to get this same result from Perl Magick but can't figure out how pass the same parameters I'm using on the command line to make it work properly. Here are a couple of variations I've tried none of which seems to have worked:

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模块我不想因为必须加载额外的模块而浪费更多的内存。我希望有人在他们的网站上已经有这个工作,并可以分享解决方案。在此先感谢您的帮助!

I know there are other ways to extract EXIF data from an image file in perl but since we already have the Perl Magick module loaded I don't want to waste any more memory by having to load an additional module. I'm hoping someone out there already has this working on their site and can share the solution. Thanks in advance for your help!

推荐答案

> 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

Version: ImageMagick 6.3.7 06/04/09 Q16 http://www.imagemagick.org

这篇关于如何使用PerlMagick提取EXIF数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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