All I need is to create a .png image with transparent background, draw some text in black on it and save it using img.save('target.png', option='optimize')
It looks like PIL saves .png images in 32-bit mode automatically. Can I reduce the color depth while not making the output images look much worse before saving? Since it contains only black text and transparent background, I think reducing the color depth would greatly reduce file size.
The
RGBA
mode is the only mode that supports transparency, and it is necessarily 32 bits:I would recommend you to store your image with a non-transparent 1 mode and use the image itself as a mask. If you give your image with mode 1 as a mask on your image, black pixels will stay and white ones will be transparent. This will take 32 times less space without any loss of information.
It will look something like this:
where
bw_image
is your black and white text.