简体   繁体   中英

How do you use ImageMagick in Perl?

I'm trying to get the command line equivalent of "identify image.png" to work in 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 .)

There is an Identify method method for PerlMagick as this documentation says.

Its parameters are: 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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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