# original image
img = Image.open('test.png')
# converted to have an alpha layer
im2 = img.convert('RGBA')
# rotated image
rot = im2.rotate(22.2, expand=1)
# a white image same size as rotated image
fff = Image.new('RGBA', rot.size, (255,)*4)
# create a composite image using the alpha layer of rot as a mask
out = Image.composite(rot, fff, rot)
# save your work (converting back to mode='1' or whatever..)
out.convert(img.mode).save('test2.bmp')
这是一个工作版本,灵感来自答案,但它没有打开或保存图像和演示如何旋转文本的工作。
这两张图片的背景颜色和alpha通道与0不同,以显示发生了什么。将两个alpha通道从92更改为0将使它们完全透明。
如果原始图像没有alpha层,则可以使用alpha层作为遮罩将背景转换为白色。当
rotate
创建“背景”时,它使其完全透明。相关问题 更多 >
编程相关推荐