Identify Returning Incorrect Height Value For Animated GIFs

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
DarseZ
Posts: 4
Joined: 2020-02-12T15:18:50-07:00
Authentication code: 1152

Identify Returning Incorrect Height Value For Animated GIFs

Post by DarseZ »

I have a batch file which I drag and drop images on to get the image dimensions. Here's part of the code in the batch:

Code: Select all

for /f "tokens=1-2" %%i in ('identify -ping -format "%%w %%h" %1') do set W=%%i & set H=%%j
echo ImgWidth is %W% 
echo ImgHeight is %H%
It works perfectly for JPG and static GIFs. With animated GIFs (with or without transparency) I tend to get odd output on H. Let's say the image size is 800x450, I get this back:

Code: Select all

ImgWidth is 800 
ImgHeight is 450800
Link to actual image file: (removed)

What could be going on? I'm presuming it's user error on my part!
Last edited by DarseZ on 2020-02-12T20:02:39-07:00, edited 1 time in total.

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

Re: Identify Returning Incorrect Height Value For Animated GIFs

Post by fmw42 »

What version of Imagemagick? What platform? I presume Windows.

On IM 6.9.10.92 Q16 Mac OSX, I get:

Code: Select all

Fredericks-Mac-mini:desktop fred$ identify Animation.gif
Animation.gif[0] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[1] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.012
Animation.gif[2] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[3] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[4] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[5] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[6] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[7] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[8] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[9] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[10] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[11] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[12] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[13] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[14] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[15] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[16] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[17] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[18] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[19] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[20] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[21] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[22] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[23] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[24] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[25] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[26] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[27] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[28] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[29] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[30] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[31] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[32] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[33] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[34] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.007
Animation.gif[35] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.007
Animation.gif[36] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[37] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[38] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[39] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[40] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.005
Animation.gif[41] GIF 800x450 800x450+0+0 8-bit sRGB 128c 9.96515MiB 0.000u 0:00.005

And

Code: Select all

identify -ping -format "%h\n" Animation.gif
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450
450

snibgo
Posts: 12863
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Identify Returning Incorrect Height Value For Animated GIFs

Post by snibgo »

I suggest you run your identify command by itself. You will see why your script doesn't do what you want.

Hint: I suppose you only want the dimension of the first frame, not all the frames.
snibgo's IM pages: im.snibgo.com

DarseZ
Posts: 4
Joined: 2020-02-12T15:18:50-07:00
Authentication code: 1152

Re: Identify Returning Incorrect Height Value For Animated GIFs

Post by DarseZ »

Hey, thanks for your reply.

I'm using 7.09.22 portable on Windows 10.

I know nothing about Imagemagick but wondering from your output why the height would also include the width in that format, 450800...almost as if the 450 and the 800 from the next field were being joined together. That's probably crazy. But I have no idea, that could just be how the output is formatted.

I'll try playing with the code (which I admit to not understanding very much).

Thanks for your time


fmw42 wrote:
2020-02-12T15:58:19-07:00
What version of Imagemagick? What platform? I presume Windows.

On IM 6.9.10.92 Q16 Mac OSX, I get:

Code: Select all

Fredericks-Mac-mini:desktop fred$ identify Animation.gif
Animation.gif[0] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[1] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.012
Animation.gif[2] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[3] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[4] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[5] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[6] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[7] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[8] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.011
Animation.gif[9] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[10] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[11] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[12] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[13] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[14] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[15] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.010
Animation.gif[16] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[17] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[18] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[19] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[20] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[21] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.009
Animation.gif[22] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[23] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[24] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[25] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[26] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[27] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[28] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.008
Animation.gif[29] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[30] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[31] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[32] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[33] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.010u 0:00.007
Animation.gif[34] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.007
Animation.gif[35] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.007
Animation.gif[36] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[37] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[38] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[39] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.006
Animation.gif[40] GIF 800x450 800x450+0+0 8-bit sRGB 128c 0.000u 0:00.005
Animation.gif[41] GIF 800x450 800x450+0+0 8-bit sRGB 128c 9.96515MiB 0.000u 0:00.005

DarseZ
Posts: 4
Joined: 2020-02-12T15:18:50-07:00
Authentication code: 1152

Re: Identify Returning Incorrect Height Value For Animated GIFs

Post by DarseZ »

Hello Snibgo, thanks for your reply. Yes, just one frame is all I need. I'll try the command line and see if anything presents itself....

snibgo wrote:
2020-02-12T16:02:17-07:00
I suggest you run your identify command by itself. You will see why your script doesn't do what you want.

Hint: I suppose you only want the dimension of the first frame, not all the frames.

snibgo
Posts: 12863
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Identify Returning Incorrect Height Value For Animated GIFs

Post by snibgo »

DarseZ wrote:...almost as if the 450 and the 800 from the next field were being joined together. That's probably crazy.
That's not crazy. That's correct. Try:

Code: Select all

identify -ping -format "%%w %%h" yourfile.gif
... to see what is happening.

You could insert a space after %%h if you want.
snibgo's IM pages: im.snibgo.com

DarseZ
Posts: 4
Joined: 2020-02-12T15:18:50-07:00
Authentication code: 1152

Re: Identify Returning Incorrect Height Value For Animated GIFs

Post by DarseZ »

Your suggestion fixed it! The revised line, with a space after the %%h, is now:

Code: Select all

for /f "tokens=1-2" %%i in ('identify -ping -format "%%w %%h " %1') do set W=%%i & set H=%%j
...and both animated GIFs and other formats parse correctly. I have to admit I find some of the syntax of that line mysterious, but I wouldn't have ever thought a space could have that effect.

thanks very much for your time on this!

Post Reply