Page 1 of 1

Composing with alpha but without blending

Posted: 2017-03-26T09:46:55-07:00
by Glidos
I'm using ImageMagick to create an image that is a patch work of other images. All the images involved have alpha channels. I first create that image and then use composite to overwrite parts of it with the other scaled and offset images - the command

Code: Select all

composite -geometry {width}x{height}+{x-offset}+{y-offset} {srcImagePath} {dstImagePath} {dstImagePath}
It almost works as I want it. The only problem is that the source images are blended with the destination image. I want the destination alpha set rather than blended (but only within the overlap rectangle). I've tried all sorts of options (-compose copy_opacity, -alpha set, -alpha on). None of them work: either I get blending, or the whole destination image is cleared, not just the part that overlaps the source.

I considered first clearing the desired area, so that the blending wouldn't matter, but I cannot work out how to do that either.

Any help much appreciated.

Re: Composing with alpha but without blending

Posted: 2017-03-26T10:07:35-07:00
by snibgo
Please say what version of IM you use, on what platform.

Personally, I wouldn't use "composite". Life is simpler with "convert".
Glidos wrote:I want the destination alpha set rather than blended (but only within the overlap rectangle).
I don't know exactly what you want. Perhaps you want the output colours to be from the colours and alphas of the two inputs (like "Over"), but the output alphas to be from the source image only. What do you want outside the overlap?

See http://www.imagemagick.org/Usage/compose/ for the options. Perhaps what you want can't be done in a simple operation.

Re: Composing with alpha but without blending

Posted: 2017-03-26T10:26:37-07:00
by Glidos
snibgo wrote: 2017-03-26T10:07:35-07:00 Please say what version of IM you use, on what platform.
Thanks for the replay. I'm using opensuse leap 42.2. Here's the version string.
Version: ImageMagick 6.8.8-1 Q16 x86_64 2017-02-21 http://www.imagemagick.org
Glidos wrote:I want the destination alpha set rather than blended (but only within the overlap rectangle).
I don't know exactly what you want. Perhaps you want the output colours to be from the colours and alphas of the two inputs (like "Over"), but the output alphas to be from the source image only. What do you want outside the overlap?
Within the overlap, I want the colours and alpha from the source image. Outside of the overlap, I want the colours and alpha from the destination image.

Re: Composing with alpha but without blending

Posted: 2017-03-26T10:52:35-07:00
by snibgo
This seems to be what you want. Windows BAT syntax. For bash, replace each ^ by \.

Destination:
Image

Source:
Image

Code: Select all

convert ^
  tc_green.png ^
  tc_red.png ^
  -gravity NorthWest ^
  -geometry +10+10 ^
  -compose Replace -composite ^
  tc_repl.png
Output:
Image

Re: Composing with alpha but without blending

Posted: 2017-03-26T10:56:15-07:00
by Glidos
snibgo wrote: 2017-03-26T10:07:35-07:00 See http://www.imagemagick.org/Usage/compose/ for the options. Perhaps what you want can't be done in a simple operation.
Ah, looking at the diagrams, I can see that your suspicion is correct and it isn't possible as a simple operation. This is what I'm after: Image
Any idea of the most simple way to do that?

Re: Composing with alpha but without blending

Posted: 2017-03-26T10:57:36-07:00
by Glidos
Ha, and just as I post that, I see you've posted a way it can be done. :-) Thank you.

Re: Composing with alpha but without blending

Posted: 2017-03-26T11:01:23-07:00
by Glidos
Yep. Just tried that and it's working just as I want it. Thanks. Works with the composite command too.