Using dispose method to reuse background

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
friendlygiraffe
Posts: 5
Joined: 2018-06-26T04:45:52-07:00
Authentication code: 1152

Using dispose method to reuse background

Post by friendlygiraffe »

Hello, I'm new to imagemagick, I was looking at ways to optimise a gif with a static background. I wondered if the first frame can be reused to save filesize - I thought perhaps using the dispose method.

Here's what I mean, I have a brick wall on the first frame, then a spinning ball on the following frames. I want the ball to spin on the brick wall background. Here is a version I created from a PNG sequence using dispose method 3 (keeping the previous image):

Image

Here is the same gif generated using dispose method 1 (removing previous image)

Image

I need the previous ball frames to dispose, keeping frame one. Is there a way to do this?

Many thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Using dispose method to reuse background

Post by snibgo »

I don't understand what is in your PNG sequence, and I'm not sure what you want for the output. I guess you want the output to be a ball in various positions against a wall. And perhaps your PNG sequence is a wall with no ball, and balls in various positions with no wall but a transparent background.

If so, then the obvious method is to compose each of the ball images over the wall, in turn:

Code: Select all

magick wall.png NULL: balls*.png -compose over -layers composite -layers optimize out.gif
Perhaps there is a better way with "-dispose".
snibgo's IM pages: im.snibgo.com
friendlygiraffe
Posts: 5
Joined: 2018-06-26T04:45:52-07:00
Authentication code: 1152

Re: Using dispose method to reuse background

Post by friendlygiraffe »

Thanks for your reply snibgo, hopefully this post will make it clearer.

The background is this, test_bg.png:

Image

The testpngs directory is a transparent png sequence containing these images:

Image

I almost got it working using this:

Code: Select all

convert -dispose none -delay 0 test_bg.png -dispose previous -delay 4 testpngs/*.png -loop 0 test.gif
This produced an amazingly small file size of 30k, but there is a pause on the first frame. This problem is referenced in the Docs here http://www.imagemagick.org/Usage/anim_basics/#cleared:

Image

I have tried various Optimisation methods, but nothing comes close to the file size of 30k.

If this is impossible to get rid of the jolt, then I was thinking OptimizeTransparency sounded promising, but I worry I'm over complicating it.

Any further ideas appreciated. I'm using ImageMagick 7.0.8-3 on a Mac via Terminal

Thanks again

snibgo wrote: 2018-06-26T08:34:23-07:00 I don't understand what is in your PNG sequence, and I'm not sure what you want for the output. I guess you want the output to be a ball in various positions against a wall. And perhaps your PNG sequence is a wall with no ball, and balls in various positions with no wall but a transparent background.

If so, then the obvious method is to compose each of the ball images over the wall, in turn:

Code: Select all

magick wall.png NULL: balls*.png -compose over -layers composite -layers optimize out.gif
Perhaps there is a better way with "-dispose".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using dispose method to reuse background

Post by fmw42 »

Please provide the two actual input images - the brick and the circling yellow dot gif.
friendlygiraffe
Posts: 5
Joined: 2018-06-26T04:45:52-07:00
Authentication code: 1152

Re: Using dispose method to reuse background

Post by friendlygiraffe »

bg image: https://imageshack.com/a/img922/926/d6c6V9.png
ball frames: https://imageshack.com/a/2Kko/1

Sorry the 49 images are separate, I couldn't find a reliable zip share site

It resizes to 160px width on output;

Code: Select all

convert -dispose none -delay 0 test_bg.png -dispose previous -delay 4 testpngs/*.png -scale 160 -loop 0 test.gif
fmw42 wrote: 2018-06-26T10:30:24-07:00 Please provide the two actual input images - the brick and the circling yellow dot gif.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using dispose method to reuse background

Post by fmw42 »

Make your set of yellow dot images into an animated gif and see if that has the jolt. Make that work first. If it does not have a jolt, then upload the animated gif for the yellow balls or zip all the pngs and upload that. I do not want to try downloading all your separate yellow ball pngs.
friendlygiraffe
Posts: 5
Joined: 2018-06-26T04:45:52-07:00
Authentication code: 1152

Re: Using dispose method to reuse background

Post by friendlygiraffe »

Sure:

Image

and bg again for reference:

Image
fmw42 wrote: 2018-06-26T10:52:55-07:00 Make your set of yellow dot images into an animated gif and see if that has the jolt. Make that work first. If it does not have a jolt, then upload the animated gif for the yellow balls or zip all the pngs and upload that. I do not want to try downloading all your separate yellow ball pngs.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using dispose method to reuse background

Post by fmw42 »

This command works fine for me in ImageMagick 6.9.10.2 Q16 Mac OSX.

Code: Select all

convert bricks.png null: \( yellow_dots.gif -coalesce \) -layers composite -layers optimize anim.gif
friendlygiraffe
Posts: 5
Joined: 2018-06-26T04:45:52-07:00
Authentication code: 1152

Re: Using dispose method to reuse background

Post by friendlygiraffe »

That works perfectly, thanks to both fmw42 & snibgo for your help
fmw42 wrote: 2018-06-26T15:43:11-07:00 This command works fine for me in ImageMagick 6.9.10.2 Q16 Mac OSX.

Code: Select all

convert bricks.png null: \( yellow_dots.gif -coalesce \) -layers composite -layers optimize anim.gif
Post Reply