Imagemagick unwanted black background on rotated transparent images

I have a website that generates polaroid images stacked on top of each other at different angles. So far, everything worked fine, but now I started to get a black background around transparent .png.
You can see the problem here . The images in the last album are all corrupted.

I am using imagemagick (6.5.4.7-3.fc12).

my commands look something like this:
the first one contains whitin foreach and generates a bunch of png, rotated at different angles

convert '{$sf}' -auto-orient -thumbnail 120x120 -gravity center -bordercolor snow -background black -polaroid {$angle} {$i}.png

the second team takes previously created images and stacks them toghater
convert '*.png' -background transparent -alpha on -gravity center -layers merge -extent 190x190 +repage -thumbnail 115x115 -gravity center -extent 120x120 'result.png'

As I understand it during debugging, a black background is already present in the images generated by the first command, and they appear only when the images are rotated. If I use -polaroid 0 instead of +polaroid , then the resulting images are fine.
I guess the problem is not with the code itself, but with ImageMagick or something else updated on my server, and this started this whole mess.

I also tried all sorts of combinations with the -alpha setting and everything else that I could find in imagemagick documents, which are even slightly related to transparency, but nothing works.

+1
source share
3 answers

After all kinds of testing, I finally came to the conclusion that the problem was not with my convert commands.

The solution to my problem was to reinstall / update ImageMagick.

+1
source

// Creates an unwanted black and white background and makes it transparent backgraund.

  ImageInfo info1 = new ImageInfo( "/opt/apache-tomcat-6.0.18/webapps/newcpclient_branch/upload/sample/ATT00003.jpg"); MagickImage blankImage = new MagickImage(info1); **blankImage.setBackgroundColor(PixelPacket.queryColorDatabase("#FFFF8800"));** blankImage = blankImage.rotateImage(250.0); blankImage.setFileName("/opt/apache-tomcat-6.0.18/webapps/newcpclient_branch/upload/sample/transparent.png"); blankImage.writeImage(info1); 
+1
source

You have -background set to black in your first line. This means that you are not getting transparency. Does it work if you set it to "none"?

Edit:

 import os import random as ra for i in range(10): image = 'convert C:/image.png -auto-orient -thumbnail 120x120 -gravity center -bordercolor snow -background none -polaroid '+str(ra.uniform(0,360))+' C:/test/image_polaroid_'+str(i)+'.png' os.system(image) image = 'convert -size 500x500 xc:transparent C:/test/result.png' os.system(image) for i in range(10): image = 'composite -gravity center C:/test/image_polaroid_'+str(i)+'.png C:/test/result.png C:/test/result.png' os.system(image) 

Edit 2:

 import os import random as ra for i in range(10): image = 'convert C:/image.png -background none -polaroid 0 C:/test/image_polaroid_'+str(i)+'.png' os.system(image) image = 'mogrify -rotate '+str(ra.randint(0,360))+' -background none C:/test/image_polaroid_'+str(i)+'.png' os.system(image) 
0
source

Source: https://habr.com/ru/post/1436619/


All Articles