Page 1 of 1

What means [0] in identify?

Posted: 2009-09-28T06:16:47-07:00
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.

Re: What means [0] in identify?

Posted: 2009-09-28T19:54:00-07:00
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.

Re: What means [0] in identify?

Posted: 2009-09-29T00:21:42-07:00
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

Re: What means [0] in identify?

Posted: 2009-09-29T10:43:40-07:00
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.

Re: What means [0] in identify?

Posted: 2009-09-29T14:39:54-07:00
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.

Re: What means [0] in identify?

Posted: 2009-09-29T16:49:03-07:00
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.

Re: What means [0] in identify?

Posted: 2009-09-29T23:24:51-07:00
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

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

Posted: 2009-09-29T23:43:31-07:00
by filchos
Addendum: an upgrade to ImageMagick-6.5.6-5 helped.

Olaf

Re: What means [0] in identify?

Posted: 2009-10-05T16:53:28-07:00
by anthony
Why use '[0]' jpegs are not a multi-image file format! it will should make no difference!

Re: What means [0] in identify?

Posted: 2009-10-05T22:29:40-07:00
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.

Re: What means [0] in identify?

Posted: 2009-10-06T11:23:50-07:00
by fmw42
worked fine for me (see above), so you probably need to upgrade your IM

Re: What means [0] in identify?

Posted: 2009-10-07T00:55:06-07:00
by filchos
That’s what I did.