I want to store a series of screenshots more efficiently by only storing their difference. Therefore I want to produce a PNG file that is fully transparent except for the parts that are different between two images.
This command basically has the desired effect (d1-2.png containing the difference between s1.png and s2.png):
composite s1.png s2.png -compose change-mask d1-2.png
However, the resulting image (d1-2.png) is still just as large as the screenshots themselves - even though it is far less complex (e.g. the background image is invisible). I think I know why: if I convert d1-2.png to JPEG (mogrify -format jpg d1-2.png), it looks exactly like s2.png - instead of also showing just the changes as d1-2.png does.
Apparently the complete image is stored and the parts that did not change are just hidden by the alpha channel. Nifty, but I don't want that.
From the looks of it, "-alpha background" should help me out ("Set any fully-transparent pixel to the background color, while leaving it fully-transparent. This can make some image file formats, such as PNG, smaller as the RGB values of transparent pixels are more uniform, and thus can compress better."). Unfortunately, it does not have any effect at all.
So, how do I make the pixels that are fully transparent a constant color so that PNG can better compress the image?
I'm using ImageMagick 6.5.6-8 2009-10-03 Q8 OpenMP on Windows XP, but ImageMagick 6.7.0-3 2011-05-26 Q16 makes no difference. Any hints? :-/
[SOLVED] Huge PNG file when using change-mask
[SOLVED] Huge PNG file when using change-mask
Last edited by Lemming on 2011-06-05T17:35:44-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Huge PNG file when using change-mask
I believe the only way to make the file size smaller would be to change the PNG file from 32-bit truecolormatte type to palettematte type. For that to work you must use -alpha background so that all transparent pixels have the same background color which is not the same color as any non-transparent pixel. So you have to be sure to use some background color that is not being used and you have to reduce your number of colors to 256 including the transparent color or let -type palettematte do that for you. Though you may have to add -colors 256.
Re: Huge PNG file when using change-mask
Awww crap, I just put the -alpha background in the wrong place... anyway, this way works:
convert s2.png s1.png -compose change-mask -composite -background white -alpha background d1-2.png
convert s2.png s1.png -compose change-mask -composite -background white -alpha background d1-2.png
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: [SOLVED] Huge PNG file when using change-mask
The change mask does NOT change any colors in the image, it only makes then transparent.
PNG files store the colors of transparenct pixels, as such you get no compression savings with change mask alone.
What you need to do is also add a -alpha background to set all fully-transparent pixels to a specific color. When you do this you will not get large tracts of pixels that are all the same, and as such get major compression!
However I can offer one time saving for a series of images. The change-mask compose was created for GIF transparency compression! That is -layers OptimizeTransparency. That create a transparency mask for MULTIPLE images.
http://www.imagemagick.org/Usage/anim_opt/#opt_trans
The first image is left as is, but the second and later images will only contain the differences between it and the previous image. It does not matter that you are not saving to GIF, you can save to PNG just as well! Try this with a series of images!
PNG files store the colors of transparenct pixels, as such you get no compression savings with change mask alone.
What you need to do is also add a -alpha background to set all fully-transparent pixels to a specific color. When you do this you will not get large tracts of pixels that are all the same, and as such get major compression!
However I can offer one time saving for a series of images. The change-mask compose was created for GIF transparency compression! That is -layers OptimizeTransparency. That create a transparency mask for MULTIPLE images.
http://www.imagemagick.org/Usage/anim_opt/#opt_trans
The first image is left as is, but the second and later images will only contain the differences between it and the previous image. It does not matter that you are not saving to GIF, you can save to PNG just as well! Try this with a series of images!
Code: Select all
convert frames_*.png -layers OptimizeTransparency \
-background white -alpha new_frames_%03d.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/