How to extract gif image to multiple png/jpg images?

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
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

How to extract gif image to multiple png/jpg images?

Post by agriz »

I want to extract gif image and then i want to join them using ffmpeg.
How do i extract those layers from gif?

Code: Select all

convert img.gif img/xx_%05d.png
Is it right?
It is not clearly extracting images from gif.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to extract gif image to multiple png/jpg images?

Post by snibgo »

That should extract the images. What happens instead? What error messages do you get? Do you get any images?

(For input to ffmpeg, each image must represent the entire frame, rather than merely a difference. So you may need other IM options, such as "-coalesce").
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: How to extract gif image to multiple png/jpg images?

Post by agriz »

I have some strange outputs.
The first frame of the gif is extracted correctly.
But the second and other frames are having only the animated part. The original image around / behind (or wherever) is missing.

But i tried to use the identify function from imagemagick. Which game me the output the of the scenes in the gif image.
If the scenes are 10, then i tried the following which game me the correct extracted images.

Code: Select all

convert img.gif[11] img/xx_%05d.png
The images are extracted like this

xx_00001-0.png
xx_00001-1.png
...

(however there was some error thrown. But the images are extracted)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to extract gif image to multiple png/jpg images?

Post by snibgo »

agriz wrote:The original image around / behind (or wherever) is missing.
snibgo wrote:(For input to ffmpeg, each image must represent the entire frame, rather than merely a difference. So you may need other IM options, such as "-coalesce").
agriz wrote:however there was some error thrown.
What was the error?
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How to extract gif image to multiple png/jpg images?

Post by glennrp »

agriz wrote:I have some strange outputs.
The first frame of the gif is extracted correctly.
But the second and other frames are having only the animated part. The original image around / behind (or wherever) is missing.
The GIF is "optimized" so only the aniimated part is present. When you show it on a display, each partial frame is written over what's
already on the screen. Use

Code: Select all

convert -coalesce img.gif[11] img/xx_%05d.png
to "Fully define the look of each frame of an GIF animation sequence".

But i tried to use the identify function from imagemagick. Which game me the output the of the scenes in the gif image.
If the scenes are 10, then i tried the following which game me the correct extracted images.

Code: Select all

convert img.gif[11] img/xx_%05d.png
The images are extracted like this

xx_00001-0.png
xx_00001-1.png
...
I guess you need to "escape" the percent-sign if you are running on some operating system where the "%" means something to the shell.
How to "escape" a symbol depends on your system. It could be "%", '%', \%, or maybe something else.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: How to extract gif image to multiple png/jpg images?

Post by agriz »

I am using fedora 17
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to extract gif image to multiple png/jpg images?

Post by fmw42 »

try

convert img.gif -coalesce img/xx_%05d.png
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: How to extract gif image to multiple png/jpg images?

Post by agriz »

fmw42 wrote:try

convert img.gif -coalesce img/xx_%05d.png
Thanks :)
works perfectly!!!
Post Reply