【问题】
代码是:
#http://stackoverflow.com/questions/5324647/how-to-merge-a-transparent-png-image-with-another-image-using-pil
import Image
background = Image.open("background.png"); #1676x343
foreground = Image.open("93873.jpg"); #512x512
background.paste(foreground, (0, 0), foreground)
background.show()结果出错:
D:\tmp\tmp_dev_root\freelance\elance\35177018_web_scrape_121\test_pic_merge>test_pic_merge.py
Traceback (most recent call last):
File "D:\tmp\tmp_dev_root\freelance\elance\35177018_web_scrape_121\test_pic_merge\test_pic_merge.py", line 10, in <module>
background.paste(foreground, (0, 0), foreground)
File "D:\tmp\WordPress\DevRoot\Python27\lib\site-packages\PIL\Image.py", line 1101, in paste
self.im.paste(im, box, mask.im)
ValueError: bad transparency mask
【解决过程】
1.去参考:
PIL Convert PNG or GIF with Transparency to JPG without
去试试
转载请注明:在路上 » 【未解决】Python中使用PIL图形库去合并png和jpg图片时出错:ValueError: bad transparency mask