7

I an trying to use Image Magick to create a new large png from several small png's but the smaller image do not have their transparency preserved. I am creating a 6000x6000 image and placing smaller png's at specific locations and some of them being rotated, this all works fine. The problem is that the small images don't have their transparency preserved when some of the small image overlap. This is an example of what I mean. I have tried several -channel options and -alpha on but nothing seems to work. What am i missing here?

enter image description here

Here is the commands I am using for my test.

convert -size 6000x6000 xc:none ^
    ( Rectangle_01.png -repage +200+200 ) ^
    ( Rectangle_01.png -repage +651+200 -rotate 45 ) ^
    ( Rectangle_01.png -repage +1102+200 -rotate -45 ) -flatten -alpha on test.png
Trevor Orr
  • 927
  • 1
  • 14
  • 31

2 Answers2

22

Did you try:

-background none

none is one of the built-in color names for a fully transparent color.

I found this question when trying to solve a similar problem with the montage command, that would not preserve transparency. Setting a transparent background did fix my problem. The default background in ImageMagick is white.

François
  • 1,831
  • 20
  • 33
  • I scrapped the image (png) method and rebuilt my app to use svg instead, was a lot of work but it gives me so much more power and flexibility in my app now. – Trevor Orr Nov 17 '14 at 21:14
5

There is a similar topic on http://www.imagemagick.org

"Try:

-fuzz XX% -transparent white

where the smaller the %, the closer to true white or conversely, the larger the %, the more variation from white is allowed to become transparent."

http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=12619

almanegra
  • 653
  • 8
  • 21
  • Finally got it to work, I originally put it this way in my script: -flatten -fuzz 10% -transparent white test.png and it did not work. This is what worked: -fuzz 10% -transparent white -flatten test.png. I had to put the flatten command last, did not think would matter but apparently it does. – Trevor Orr Apr 07 '14 at 20:58
  • Yea it sure does, cause the -flatten command basically "finishes" all the operations you just did, putting all together :) regards – almanegra Apr 07 '14 at 21:32