PIL Convert PNG or GIF with Transparency to JPG without

前端 未结 3 965
既然无缘
既然无缘 2020-11-28 13:35

I\'m prototyping an image processor in Python 2.7 using PIL1.1.7 and I would like all images to end up in JPG. Input file types will include tiff,gif,png both with transpar

3条回答
  •  醉梦人生
    2020-11-28 14:14

    Make your background RGB, not RGBA. And remove the later conversion of the background to RGB, of course, since it's already in that mode. This worked for me with a test image I created:

    from PIL import Image
    im = Image.open(r"C:\jk.png")
    bg = Image.new("RGB", im.size, (255,255,255))
    bg.paste(im,im)
    bg.save(r"C:\jk2.jpg")
    

提交回复
热议问题