美文网首页
python使用PIL把透明背景图片转成白色背景

python使用PIL把透明背景图片转成白色背景

作者: 疯人愿的疯言疯语 | 来源:发表于2023-07-27 14:07 被阅读0次

    (53条消息) python使用PIL把透明背景图片转成白色背景_python全部底图改成白底图_Dxy1239310216的博客-CSDN博客

    做个记录

    from PIL import Image
     
    imagePtah = r'E:\Python\test1.png'
    img = Image.open(imagePtah)
    if img.mode != 'RGBA':
        img = img.convert('RGBA')
    width = img.width
    height = img.height
     
    img2 = Image.new('RGB', size=(width, height), color=(255, 255, 255))
    img2.paste(img, (0, 0), mask=img)
     
    img2.show()
    

    相关文章

      网友评论

          本文标题:python使用PIL把透明背景图片转成白色背景

          本文链接:https://www.haomeiwen.com/subject/vcwlpdtx.html