Paste an image without it's transparency.

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
Dus
Posts: 9
Joined: 2013-04-16T04:57:39-07:00
Authentication code: 6789

Paste an image without it's transparency.

Post by Dus »

I've searched the fora for a way to paste one image onto another and in this thread viewtopic.php?f=1&t=23858 I found:

Code: Select all

convert backgroundimage foregroundimage -gravity center -compose over -composite resultimage
Which works except the transparency of the "foregroundimage" gets copied as well. Meaning part of the non-transparent area of the "backgroundimage" has now become semi-transparent. (transparency getting averaged it seems).

How can I copy the foregroundimage while keeping non-transparent parts of the backgroundimage non-transparent?
I use ImageMagick-6.8.4-10-Q16-x86-windows and all images are pngs made using

Code: Select all

convert input.bmp mask.bmp -compose CopyOpacity -composite result.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Paste an image without it's transparency.

Post by snibgo »

You can turn off the alpha channel in foregroundimage. All pixels from foregroundimage will be opaque.

Code: Select all

convert backgroundimage ( foregroundimage -alpha off ) -gravity center -compose over -composite resultimage
If you don't use parentheses, alpha is turned off in both images:

Code: Select all

convert backgroundimage foregroundimage -alpha off -gravity center -compose over -composite resultimage
See http://www.imagemagick.org/script/comma ... .php#alpha
snibgo's IM pages: im.snibgo.com
Dus
Posts: 9
Joined: 2013-04-16T04:57:39-07:00
Authentication code: 6789

Re: Paste an image without it's transparency.

Post by Dus »

If I turn alpha channel off in the foregroundimage I see a big white blob where the other (background) image should be.

Maybe this is a better way to say it:
foregroundimage transparent area + backgroundimage non-transparent area = non-transparent backgroundimage and
foregroundimage non-transparent area + backgroundimage transparent area = non-transparent foregroundimage

The non-transparent parts should not overlap and overlapping transparency parts can stay transparent.

BTW:

Code: Select all

mogrify -gravity center -draw "image Over 0,0 0,0 'transparent0.png'"
also gives semi-transparent images.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Paste an image without it's transparency.

Post by snibgo »

Sorry, I don't understand what you want. You can post sample images to dropbox.com or similar and paste the links here, then explain what you want.
snibgo's IM pages: im.snibgo.com
Post Reply