Composing with alpha but without blending

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
Glidos
Posts: 5
Joined: 2017-03-26T09:33:13-07:00
Authentication code: 1151

Composing with alpha but without blending

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composing with alpha but without blending

Post 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.
snibgo's IM pages: im.snibgo.com
Glidos
Posts: 5
Joined: 2017-03-26T09:33:13-07:00
Authentication code: 1151

Re: Composing with alpha but without blending

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composing with alpha but without blending

Post 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
snibgo's IM pages: im.snibgo.com
Glidos
Posts: 5
Joined: 2017-03-26T09:33:13-07:00
Authentication code: 1151

Re: Composing with alpha but without blending

Post 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?
Glidos
Posts: 5
Joined: 2017-03-26T09:33:13-07:00
Authentication code: 1151

Re: Composing with alpha but without blending

Post by Glidos »

Ha, and just as I post that, I see you've posted a way it can be done. :-) Thank you.
Glidos
Posts: 5
Joined: 2017-03-26T09:33:13-07:00
Authentication code: 1151

Re: Composing with alpha but without blending

Post by Glidos »

Yep. Just tried that and it's working just as I want it. Thanks. Works with the composite command too.
Post Reply