2011-09-26 80 views
4

我試圖讓命令行等價於「identify image.png」在Perl中工作。你如何在Perl中使用ImageMagick?

你如何去做這件事?

謝謝。

更新: 我有以下代碼

 use Image::Magick;  
    $image = Image::Magick->new; 
    open(IMAGE, 'image.gif'); 
    $image->Identify(file => \*IMAGE); 
    close(IMAGE); 

但得到以下錯誤:

Can't locate Image/Magick.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .)

回答

5

沒有爲PerlMagick的Identify方法方法this documentation說。

它的參數是:file=>file, features=>distance, unique=>{True, False}

所以它可以像這樣被使用(測試):

use Image::Magick; 

$image = Image::Magick->new; 
open(IMAGE, 'image.gif'); 
$image->Read(file => \*IMAGE); 
close(IMAGE); 
$image->Identify(); 

如果您只需要尺寸:

use Image::Magick; 

$image = Image::Magick->new; 
my ($width, $height, $size, $format) = $image->Ping('image.gif'); 
+0

我只是得到能'image :: Magick「(可能你忘了加載」Image :: Magick「?)在image.pl第4行找到對象方法」new「。 – gbhall

+0

做過喲你加載模塊? '使用Image :: Magick;' –

+0

是剛剛更新我的帖子,以反映這一點,但然後我得到上面顯示在我編輯後的錯誤 – gbhall