在PNG中将图像另存为RGBA8

时间:2016-01-05 12:14:37

标签: python png python-imaging-library

我正在尝试在PNG中保存图像,并希望保持透明度并优化尺寸。 64种颜色就足够了。

我想我已经有了Python枕头的解决方案,但已经失去了它。这是我正在寻找的结果(RGBA PNG有64种颜色):

enter image description here

我正在尝试这个:

tile_opt = tile.convert("RGB").convert("P", palette=Image.ADAPTIVE, colors=64)
tile_opt.save(currenttiles_path + "/" + fname, "PNG", optimize=True)

但我在convert("RGB")失去了alpha。如果我尝试convert("RGBA"),那么Python说图像的格式不正确。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我使用pngquantwebsite)解决了这个问题。

我仍然需要弄清楚如何在Python中使用该模块,但是能够通过使用os.system()从Python调用以下命令来获得正确的结果:

pngquant ---output final.png 64 original.png

相关问题