Page 1 of 1

How to convert a specific frame using a batch file

Posted: 2012-06-28T03:54:38-07:00
by Chaka
Hi All

Still new to IM but have been doing basic stuff so far - converting gif/bmd/png
This is using batch file on Win7 cmd.exe and IM 6.7.7-9.

I now have to convert *.ico to *.xpm which I can do fine one ico file at a time.
First identify to see which frame is 128x128
D:\>identify icon1.ico
icon1.ico[0] ICO 16x16 16x16+0+0 32-bit DirectClass 82.7KB 0.000u 0:00.002
icon1.ico[1] ICO 32x32 32x32+0+0 32-bit DirectClass 82.7KB 0.000u 0:00.015
icon1.ico[2] ICO 48x48 48x48+0+0 32-bit DirectClass 82.7KB 0.000u 0:00.022
icon1.ico[3] ICO 128x128 128x128+0+0 32-bit DirectClass 82.7KB 0.000u 0:00.032

Then use: convert icon1.ico[3] icon1.xpm

I would like to do this in the batch file as well and not sure how. Did a search on this board but have not found anything (that makes sense to me)

How can I get the correct frame when running the batch?
- Is there another option apart from 'identify' that I can use?
- Or is this something I should do via the batch to iterate through the identify results? If this is the case, any suggestions on how to do this?

Thanks!

Re: How to convert a specific frame using a batch file

Posted: 2012-06-28T09:48:50-07:00
by fmw42
You will have to write a script to find the frame of the correct size and process it. But you can use

convert yourimage.ico -format "%wx%h" info:

to just get the widhtxheight for each frame

or


convert yourimage.ico -format "%s %wx%h" info:

to get the frame number as well

see
http://www.imagemagick.org/script/escape.php

Re: How to convert a specific frame using a batch file

Posted: 2012-07-12T01:34:15-07:00
by Chaka
Ended up with this.

Run this loop for every image specifying the wxh to look for and the correct scene is returned for the conversion.
Still have a snag where you can end up in a indefinite loop if you add this code for each image. For now I specify a different variable for each image (set=a, set=b etc).
Need to look into better handling.

Code: Select all

set a=0
:loop
convert icon.ico -format "%%s %%wx%%h" info: | find "%a% 128x128"
if %errorlevel% EQU 0 goto break
set /a a+=1
goto loop
:break
convert icon.ico[%a%] icon1.xpm