Converting PNG32 to PNG8 with PIL while preserving transparency

前端 未结 4 968
悲哀的现实
悲哀的现实 2020-12-16 04:48

I would like to convert a PNG32 image (with transparency) to PNG8 with Python Image Library. So far I have succeeded converting to PNG8 with a solid background.

Belo

4条回答
  •  我在风中等你
    2020-12-16 05:33

    As mentioned by Mark Ransom, your paletized image will only have one transparency level.

    When saving your paletized image, you'll have to specify which color index you want to be the transparent color like this :

    im.save("logo_py.png", transparency=0) 
    

    to save the image as a paletized colors and using the first color as a transparent color.

提交回复
热议问题