Create animated GIF from PNG with all frames in one file

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
cybersaga
Posts: 4
Joined: 2019-06-04T12:08:00-07:00
Authentication code: 1152

Create animated GIF from PNG with all frames in one file

Post by cybersaga »

I have a PNG file that has all of the frames of an animation stacked on top of each other. It's a 40x40 image, so the first frame is at 0,0. The second frame is at 0,40... etc. I'd like to extract those frames into an animated GIF.

Now, I actually have 110 of such files, each with a different number of frames, so I'm hoping this can be done without specifying the number of frames.

Is there a way to do this?

I know it could be done easily if each frame was in its own file, so the next best solution is splitting them into multiple files, but I don't know how to do that either - but again, I'd have to split them without specifying the number of frames, so I can do a batch job on all of the files.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create animated GIF from PNG with all frames in one file

Post by snibgo »

What version of IM, on what platform?

PNG files contain only one image. I think you mean that the file contains all the frames in a single image, with the frames appended vertically. Each frame is 40 pixels high.

Code: Select all

magick in.png -crop x40 +repage out.gif
This splits the input into frames, and makes a GIF from it.

Does that work?
snibgo's IM pages: im.snibgo.com
cybersaga
Posts: 4
Joined: 2019-06-04T12:08:00-07:00
Authentication code: 1152

Re: Create animated GIF from PNG with all frames in one file

Post by cybersaga »

Yes! That works wonderfully. Thank you. I knew it must be easy.

Now the frames have a transparent background and each frame is being written over the last one. I tried using "-dispose previous" and "-dispose background" but neither have any effect.

Is there a way to clear the canvas between frames?
cybersaga
Posts: 4
Joined: 2019-06-04T12:08:00-07:00
Authentication code: 1152

Re: Create animated GIF from PNG with all frames in one file

Post by cybersaga »

I found this: http://www.imagemagick.org/discourse-se ... hp?t=33974

I just need to put "-dispose previous" before the input file.

Thanks again!
cybersaga
Posts: 4
Joined: 2019-06-04T12:08:00-07:00
Authentication code: 1152

Re: Create animated GIF from PNG with all frames in one file

Post by cybersaga »

And I'm using 7.0.8-48 Q16 x64 on Windows 10.
Post Reply