Transparency is considered as black in windows and in program
I'm using the PIL python library to do some batch copy-pasting from image to image. I had it working yesterday, but s开发者_JAVA百科uddenly when I restarted my computer, the program considers transparency as black, and also, the image pasted in uses the palette of the image being pasted into. Hope that's not too confusing.. Here's my code
import Image
imagein = Image.open("ramza.png")
imagein.show()
x, y, w, h = (0, 0, 128, 128)
box = (x, y, x + w, y + h)
region = imagein.crop(box)
imageout = Image.open("Template.png")
imageout.show()
imageout.paste(region, box)
imageout.show()
imageout.save("fn.png")
To be sure your pasted region is blended with the template image using the region's alpha layer, use the mask
keyword argument and use the region image as the mask. It will automatically use the alpha layer to blend.
Here's the code:
import Image
imagein = Image.open("png-transparency.png")
x, y, w, h = (0, 0, 128, 128)
box = (x, y, x + w, y + h)
region = imagein.crop(box)
imageout = Image.open("bigtest1.jpg").convert('RGBA')
imageout.paste(region, box, mask=region)
imageout.save("fn.png")
I don't know how to proceed with your palette question. Perhaps you could post some sample images with different palettes that demonstrate the issue?
精彩评论