Using the image array vs. the root image for attributes

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
rismanma
Posts: 1
Joined: 2014-01-13T09:25:19-07:00
Authentication code: 6789

Using the image array vs. the root image for attributes

Post by rismanma » 2014-01-13T09:41:10-07:00

I'm encountering an issue trying to read a .jpg file and see whether it is interlaced. To test, I'm using an image that I know to be interlaced. Here is the code I'm using:

Code: Select all

perl -MImage::Magick -e'my $i=Image::Magick->new; $i->Read("media/ProgressiveExample1-msuqBz.jpg"); warn $i->Get('interlace');'
None at -e line 1.
So this seems to be telling me it's not interlaced.

However, I decided to try to access the same image as an array ref, and this time, the result I got was that it is interlaced:

Code: Select all

perl -MImage::Magick -e'my $i=Image::Magick->new; $i->Read("media/ProgressiveExample1-msuqBz.jpg"); warn $i->[0]->Get('interlace');'
JPEG at -e line 1.
Just to be sure, I looked to see if there were any other images in the array, and there weren't any:

Code: Select all

perl -MImage::Magick -e'my $i=Image::Magick->new; $i->Read("media/ProgressiveExample1-msuqBz.jpg"); warn $i->[1]->Get('interlace');'
Can't call method "Get" on an undefined value at -e line 1.
So I was able to work around this by using object->[0] instead of the object itself. What I am wondering is why this is? I spend a whole bunch of time trying to figure this out before thinking to use object->[0], so I am wondering if I missed something. I'm still mostly a novice using ImageMagick, so it could be just that I don't yet know how to do this properly.

I also verified with the command line that I can see that the image is interlaced, so I thought that just calling object->get('interlace') would give me the same information, but it doesn't:

Code: Select all

identify -verbose media/ProgressiveExample1-msuqBz.jpg | grep Interlace
  Interlace: JPEG

Phantom7
Posts: 5
Joined: 2014-02-10T15:31:48-07:00
Authentication code: 6789

Re: Using the image array vs. the root image for attributes

Post by Phantom7 » 2014-02-10T17:40:25-07:00

The first element in a perl array ever will be "0" ... formerly seen as @array[0] or $array[0].

Post Reply