Merging transparency with a png

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
dra

Merging transparency with a png

Post by dra »

I have two 7x7 pixel PNG files. One contains a red triangle with the other half of the image being fully transparent white; the other image is totally opaque. I'm trying to create a 47x7 PNG which has the one image at the left and the other at the right with a similarly transparent white background. I've tried saying:

convert -size 47x7 xc:transparent Triangle.png -geometry +40+0 -composite 1.png -composite New.png

This gives me a 47x7 PNG with a transparent background with the image from 1.png on the left and the image from Triangle.png on the right. However, the transparent region from Triangle.png shows up in solid black. I've tried playing with the -alpha option (and tried reading lots of similar examples in the docs) but can't get it to copy the transparency through.

Any help much appreciated!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Merging transparency with a png

Post by fmw42 »

try


convert -size 47x7 xc:none -gravity west Triangle.png -composite -gravity east 1.png -composite New.png

or

convert Triangle.png -size 33x7 xc:none 1.png +append New.png

If those don't work, then provide links to your two input images so we can see if they have any problems.
dra

Re: Merging transparency with a png

Post by dra »

Afraid that both of those actually put Triangle.png and 1.png the other way around and the transparency from Triangle.png still gets turned to black.

I've uploaded http://romulus.metastack.com/files/magick.zip which contains the two source files Triangle.png and 1.png, the result I'm getting with my command in New.png and also Required.png which is what I'm trying to get!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Merging transparency with a png

Post by fmw42 »

These two commands work perfectly for me on IM 6.6.4.6 Q16 Mac OSX Tiger. No black showing from the Triangle.png image. Note I switched the images or the gravity settings to reverse the image order to get what you wanted.


convert -size 47x7 xc:none -gravity east Triangle.png -composite -gravity west 1.png -composite New1.png

convert 1.png -size 33x7 xc:none Triangle.png +append New2.png


What version of IM are you using? Perhaps you need to upgrade.
dra

Re: Merging transparency with a png

Post by dra »

:oops: How embarrassing - I was so convinced that it was simply that I was doing something wrong with a switch that I didn't consider it could be a bug and check for later versions - I was running 6.6.1 from when I built this machine in May... 6.6.4 works fine.

Thanks for the help!
Post Reply