anthony wrote:your final example results seems to indicate you are wanting to define the background of a GIF image that only has boolean transparency, in termes of a web page background.
That is you want to replace semi-transparency with an appropriate opaque color blend, while keeping fully-transparent transparent and fully-opaque opaque.
Yes, pretty much.
(Similar to what the
Semi-Flatten filter in Gimp does).
anthony wrote:If so, say so, rather than what you think you want!
The reason I didn't is that I
wasn't looking for a generic manual solution for "somehow make anti-aliased GIF look good for a given background color/pattern, no matter the details", but rather a very specific solution that ties in with an existing scripted work-flow, in which an anti-aliased foreground image of arbitrary shape has already been generated as PNG, as have one or more background images of the same dimensions which provide the (approximate) color values of certain parts of the web page background which the GIF image will be shown on.
I do admit however that the abstract example images I gave weren't really sensible use cases of this problem/solution (I didn't use real-life images as the ones I had at hand were really small), and my original description of the problem might not have been as clear as I intended. Sorry about that.
anthony wrote:You are better off using a 'average' or 'solid' color that roughly matches the whole background for the task.
No, not necessarily.
Imagine a GIF image that represents the edge or corner of an outlined/shadowed box on a web page. The background color/pattern inside the box might be different from the background color/pattern outside the box, so in the GIF image the pixels belonging to the "inside" of the box need to be semi-flattened against a different color than the pixels belonging to the "outside" of the box.
Anyways in the work-flow mentioned above, the information about which pixel should be semi-flattened against which color already exists, in the form of the given background image(s).
anthony wrote:In BOTH cases you can just overlay the semi-transparent image on your background pattern or average color, then find what pixels did not change, to generate a mask of the image.
One method is shown in Change Mask Composition.
http://www.imagemagick.org/Usage/compose/#changemask
Whcih will directly produce what you want.
Code: Select all
convert imbackground.png \( +clone imsource.png -composite \) \
-fuzz 25% -compose ChangeMask -composite output.gif
When removing the
-fuzz option, this produces something very similar to the result of the first two steps of my 3-step solution above:
+
=
The third step (overlaying the source image on this masked background) would still have to be done as a separate command though, right?