最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】Python中使用PIL图形库去合并png和jpg图片时出错:ValueError: bad transparency mask

Python crifan 10708浏览 0评论

【问题】

代码是:

#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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.332 seconds, using 22.10MB memory