sprite sheets to animated .gif files

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
Voyager
Posts: 3
Joined: 2015-12-30T10:04:56-07:00
Authentication code: 1151

sprite sheets to animated .gif files

Post by Voyager »

Good day everyone! It's my first time trying to do something like this. I tried many things but finally gave up :(
I have over 200 sprite sheet .png files that I want to convert to animated .gif files (then if possible change extension to .png, not format)
Windows 8.1 and ImageMagick-6.9.2-10-Q16-x64

here is an example https://dl.dropboxusercontent.com/u/609 ... xample.png

this works for one file

Code: Select all

convert -dispose 3 -delay 4 -loop 0 *.png -crop 80x80 +repage result.gif
https://dl.dropboxusercontent.com/u/609 ... result.gif

for all the files I tried mogrify but "mogrify.exe: unable to open image '*.gif'"

Code: Select all

mogrify -dispose 3 -delay 4 -loop 0 *.png -crop 80x80 +repage *.gif
so I tried this but mogrify seems to ignore +repage

Code: Select all

mogrify -format gif *.png
mogrify -dispose 3 -delay 4 -loop 0 *.gif -crop 80x80 +repage *.gif
https://dl.dropboxusercontent.com/u/609 ... ck/bad.gif
:?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sprite sheets to animated .gif files

Post by fmw42 »

mogrify does not specify the input image. It takes all images of -format specified in a folder and makes them into the suffix specified at the end. Basically, one output for each input, only. So you cannot make multiple outputs for each input with mogrify. You will have to write a script loop over each image in the folder and use convert to generate the multiple gif files. see http://www.imagemagick.org/Usage/basics/#mogrify

Also note that PNG does not support animation, so if you convert to png, you will get individual images for each frame.
Voyager
Posts: 3
Joined: 2015-12-30T10:04:56-07:00
Authentication code: 1151

Re: sprite sheets to animated .gif files

Post by Voyager »

did some research. came up to this and for some reason it works

Code: Select all

mogrify -format gif *.png
FOR %%? IN (*.gif) DO mogrify -dispose 3 -delay 4 -loop 0 *.gif -crop 80x80 +repage *.gif %%?
then if I use this it creates .gif with all the previous .png

Code: Select all

mogrify -format gif *.png
FOR %%? IN (*.gif) DO convert -dispose 3 -delay 4 -loop 0 *.gif -crop 80x80 +repage *.gif %%?
as for changing extention to .png I don't want to change the format, only the extension
from this https://dl.dropboxusercontent.com/u/609 ... result.gif
to this https://dl.dropboxusercontent.com/u/609 ... result.png
they are both animated
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sprite sheets to animated .gif files

Post by fmw42 »

I do not see a difference between your two sets of command?

I advise against just editing the file suffix from gif to png. Image readers may be confused by the png suffix on gif file. In any case it is "bad form" to do so.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: sprite sheets to animated .gif files

Post by snibgo »

Voyager wrote:as for changing extention to .png I don't want to change the format, only the extension
Why do you want to do this? The ordinary Windows command can do that ...

Code: Select all

ren *.gif *.png
... but I can't see why you would want to. It seems like a bad idea.
snibgo's IM pages: im.snibgo.com
Voyager
Posts: 3
Joined: 2015-12-30T10:04:56-07:00
Authentication code: 1151

Re: sprite sheets to animated .gif files

Post by Voyager »

fmw42, the difference is in the second line, one using mogrify and the other convert

thanks for that command snibgo!
just personal stuff :D in discord, a voice and text chatting program, a .gif file is overlayed with the text "GIF" while .png not

and btw
found out this converts all sprite sheets to animated .gif files in seconds

Code: Select all

mogrify -format gif *.png
mogrify -dispose 3 -delay 4 -loop 0 *.gif -crop 80x80 *.gif
mogrify *.gif +repage *.gif
thank you :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sprite sheets to animated .gif files

Post by fmw42 »

You have to run 3 mogrify commands. You should be able to write a simple loop over each image in the directory and create an animated gif in one convert command.

loop over each image
get filename (without suffix)
convert filename.png -dispose previous -delay 10 -crop 80x80 +repage -loop 0 filename.gif
end loop

I do not use windows, but this would be trivial in unix.

Code: Select all

cd directory
list=`ls *.png`
for img in $list; do
filename=$(convert $img -format "%t" info:)
convert $img -dispose previous -delay 10 -crop 80x80 +repage -loop 0 $filename.gif
done
Post Reply