问题
I have a website that generates polaroid-like images stacked on eachother at different angles.
Up until now everything worked well, but now i've started getting some black background around my transparent .png's.
You can see the problem here. The images in the last album are all messed up.
I'm using imagemagick (6.5.4.7-3.fc12).
my commands look something like this:
the first one is contained whitin a foreach and generates a bunch of pngs rotated at different anglesconvert '{$sf}' -auto-orient -thumbnail 120x120 -gravity center -bordercolor snow -background black -polaroid {$angle} {$i}.png
the second command takes the previously generated images and stacks them toghaterconvert '*.png' -background transparent -alpha on -gravity center -layers merge -extent 190x190 +repage -thumbnail 115x115 -gravity center -extent 120x120 'result.png'
As far as I got with the debuging, the black background is already present in the images generated with the first command and they only appear when I rotate the images. If I only use -polaroid 0
instead of the +polaroid
, then the resulting images are ok.
My guess is that the problem is not with the code itself, but rather ImageMagick or something else got upgraded on my server and that started this whole mess.
I also tried all kinds of combinations with setting -alpha
and everything else i could find in the imagemagick docs that is even just slightly related to transparency, but nothing seems to work.
回答1:
After all sorts of testing I finally got to the conclusion that the problem was not with my convert
commands.
The solution to my problem was to reinstall/update ImageMagick.
回答2:
//It romove the unwanted black/white background and make 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);
回答3:
You have -background set to 'black' in your first line. That means you don't get 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)
来源:https://stackoverflow.com/questions/9276975/imagemagick-unwanted-black-background-on-rotated-transparent-images