简体   繁体   English

你如何在Perl中使用ImageMagick?

[英]How do you use ImageMagick in Perl?

I'm trying to get the command line equivalent of "identify image.png" to work in Perl. 我试图让命令行等同于“识别image.png”在Perl中工作。

How do you go about doing this? 你是怎么做的?

Thanks. 谢谢。

Update: I have the following code 更新:我有以下代码

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

But get the following error: 但是得到以下错误:

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 .) 无法在@INC中找到Image / Magick.pm(@INC包含:/ 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。)

There is an Identify method method for PerlMagick as this documentation says. 正如本文档所述 ,PerlMagick有一种Identify方法方法。

Its parameters are: file=>file, features=>distance, unique=>{True, False} 它的参数是: file=>file, features=>distance, unique=>{True, False}

So it could be used like this ( tested ): 所以它可以这样使用( 测试 ):

use Image::Magick;

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

If you need only the dimensions: 如果您只需要尺寸:

use Image::Magick;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM