Page 1 of 1
Using dispose method to reuse background
Posted: 2018-06-26T05:14:50-07:00
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):
Here is the same gif generated using
dispose method 1 (removing previous image)
I need the previous ball frames to dispose, keeping frame one. Is there a way to do this?
Many thanks
Re: Using dispose method to reuse background
Posted: 2018-06-26T08:34:23-07:00
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".
Re: Using dispose method to reuse background
Posted: 2018-06-26T09:54:45-07:00
by friendlygiraffe
Thanks for your reply snibgo, hopefully this post will make it clearer.
The background is this,
test_bg.png:
The
testpngs directory is a transparent png sequence containing these images:
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:
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".
Re: Using dispose method to reuse background
Posted: 2018-06-26T10:30:24-07:00
by fmw42
Please provide the two actual input images - the brick and the circling yellow dot gif.
Re: Using dispose method to reuse background
Posted: 2018-06-26T10:48:27-07:00
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.
Re: Using dispose method to reuse background
Posted: 2018-06-26T10:52:55-07:00
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.
Re: Using dispose method to reuse background
Posted: 2018-06-26T11:11:08-07:00
by friendlygiraffe
Sure:
and bg again for reference:
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.
Re: Using dispose method to reuse background
Posted: 2018-06-26T15:43:11-07:00
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
Re: Using dispose method to reuse background
Posted: 2018-06-27T06:29:49-07:00
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