What means [0] in identify?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
filchos

What means [0] in identify?

Post by filchos »

Hello,

while solving a problem with a Ruby On Rails plugin called „paperclip“ I found the plugin calling

Code: Select all

identify -format "%wx%h" /path/to/file[0]
which returned a double width and a double height of the identified jpeg, e.g. 800x600 instead of 400x300.

Just calling

Code: Select all

identify -format "%wx%h" /path/to/file
works as expected giving the correct height and width of the image.

Does anybody now where the [0] stands for?

I use ImageMagick 6.4.8-7 on Mac OS X 10.5

Thanks in advance,
Olaf

P.S.: /path/to/file is of course just a replacement to improve the readability.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: What means [0] in identify?

Post by fmw42 »

it is the first frame of a multi-frame image such as a gif animation or a multipage PDF or the first layer of a PSD file, etc.
filchos

Re: What means [0] in identify?

Post by filchos »

Hi fmw42,

thank you for the info. Do you know, why the image dimensions aren’t correct when using [0] on jpegs? Is this only an error on my machine or a bug?

Olaf
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: What means [0] in identify?

Post by fmw42 »

what happens when you leave the [0] and run

identify -format "%wx%h" /path/to/file

you will get a row for each frame as output

[0]...
[1]...

etc

Also what do you get from

identify -verbose /path/to/file

You could have a virtual-canvas issue, but I was told that jpgs do not use the virtual canvas.

How do you know that the size is twice as big as you think it should be? How did you measure the true size?

What version of IM are you using?

If you run the above commands outside of Ruby, what do you get. Might it be a Ruby on Rails issue?

Can you post a link to your image? Then someone can run identify on it to verify what you have.
filchos

Re: What means [0] in identify?

Post by filchos »

fmw42 wrote:what happens when you leave the [0] and run identify -format "%wx%h" /path/to/file
I just get „928x300“. Adding [0] I get „1856x600“ instead.
fmw42 wrote:Also what do you get from identify -verbose /path/to/file
I get (excerpt):

Code: Select all

Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 928x300+0+0
Resolution: 100x100
[…]
Page geometry: 928x300+0+0
fmw42 wrote:How do you know that the size is twice as big as you think it should be? How did you measure the true size?
I used Photoshop CS4 to create the image. Additionally I used Firefox and the Apple Infobox to show the images dimensions.
fmw42 wrote:What version of IM are you using?
identify --version displays

Code: Select all

Version: ImageMagick 6.4.8-7 2009-09-28 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
fmw42 wrote:If you run the above commands outside of Ruby, what do you get. Might it be a Ruby on Rails issue?
I ran all commands from the command line (bash) to ensure that this is neither a Ruby nor a Rails issue.
fmw42 wrote:Can you post a link to your image? Then someone can run identify on it to verify what you have.
Yes, the image is found at http://foto.olafschneider.de/pics/2005/ ... klaren.jpg

Thanks a lot for your detailed questions, I hope my answers help to solve the problem.
Olaf

[edited]:
The problem seems to exist for all jpegs. The calculation of gif images seems to be ok.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: What means [0] in identify?

Post by fmw42 »

try putting the file in quotes

identify -verbose "/path/to/file[0]"


identify "aufklaren.jpg[0]"
aufklaren.jpg[0]=>aufklaren.jpg JPEG 928x300 928x300+0+0 8-bit DirectClass 68.7KiB


But if you do not have multiple frames why even bother adding [0]. No need for it.


Nevertheless, it works for me:

identify -format "%wx%h" aufklaren.jpg
928x300

identify -format "%wx%h" aufklaren.jpg[0]
928x300

identify -format "%wx%h" "aufklaren.jpg[0]"
928x300

Perhaps you have a corrupted IM or need to upgrade.
filchos

Re: What means [0] in identify?

Post by filchos »

Hi fmw42,

using quotes doesn’t change the output.

So it looks like I’m having a corrupted version of image magick on my computer.

I installed image magick using the following shell script: http://github.com/maddox/magick-installer. Now I’ll look for an alternative way of installation.

Thank you very much for helping me,
Olaf
filchos

Re: What means [0] in identify? [solved]

Post by filchos »

Addendum: an upgrade to ImageMagick-6.5.6-5 helped.

Olaf
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: What means [0] in identify?

Post by anthony »

Why use '[0]' jpegs are not a multi-image file format! it will should make no difference!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
filchos

Re: What means [0] in identify?

Post by filchos »

OK,

back to Ruby (and to the 1st post):

The [0] suffix is part of the Rails plug in “paperclip” that handles file uploads. Since you can upload (animated) gifs as well, the [0] is sensible and (as you have mentioned) makes no difference in jpegs.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: What means [0] in identify?

Post by fmw42 »

worked fine for me (see above), so you probably need to upgrade your IM
filchos

Re: What means [0] in identify?

Post by filchos »

That’s what I did.
Post Reply