Reputation: 6150
I am trying to save an image in PNG and would like to preserve transparency and optimize for size. 64 colors are enough.
I think I already had the solution with Python's Pillow, but have lost it. Here is the result I'm looking for (RGBA PNG with 64 colors):
I'm trying with this:
tile_opt = tile.convert("RGB").convert("P", palette=Image.ADAPTIVE, colors=64)
tile_opt.save(currenttiles_path + "/" + fname, "PNG", optimize=True)
But I am loosing alpha with convert("RGB")
. If I try convert("RGBA")
then Python says image is not in right format.
How can I do this?
Upvotes: 2
Views: 941
Reputation: 6150
I solved this using pngquant (website).
I still have to figure out how to use the module within Python but was able to get proper result by invoking the following command from Python with os.system()
:
pngquant ---output final.png 64 original.png
Upvotes: 1