filename.gif to filename_01.png, filename_02.png, etc.

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
Edistra
Posts: 1
Joined: 2015-11-28T07:16:02-07:00
Authentication code: 1151

filename.gif to filename_01.png, filename_02.png, etc.

Post by Edistra »

Hello,

Despite some researches I can't manage to do what I want.

I have several .gif files which contain animations that I want to split into several frames, so I use :

Code: Select all

convert -coalesce walk.gif -set filename:f '%t' 'walk_%02d.png'
and get walk_01.png, walk_02.png, etc. perfect.

Now I would like to write a generic function and replace "walk" by the filename and be able to execute the command only one time for all the .gif files.
I tried many things like :

Code: Select all

convert -coalesce *.gif -set filename:f '%t_%02d' '%[filename:f].png'
or

Code: Select all

convert -coalesce *.gif -set filename:f '%t' '%[filename:f]_%02d.png'
but nothing works properly, it seems that the second expression with % is ignored.

Does anyone know how to do that ? :D
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: filename.gif to filename_01.png, filename_02.png, etc.

Post by fmw42 »

This will do what you want, but it won't put leading zeros in there.

Code: Select all

convert *.gif -coalesce -set filename:f '%t_%s' '%[filename:f].png'
This does it for one image, so you would need to write a loop over each image.

Code: Select all

filename=`convert image.gif -format "%t\n" info: | head -n 1`
convert image.gif -coalesce  ${filename}_%02d.png
It almost works in the reverse order:

Code: Select all

convert image.gif  -coalesce -set filename:f '%t' %02d_%[filename:f].png
Post Reply