PIL image.getcolors

R

Robin Becker

I have an RGBA .png which PIL is able to read and I would like to convert the
image to a simple RGB image with a single colour reserved for transparent as the
A channel is either all on or all off.

I thought I could use the the im.getcolors method to find the colours used by
the image, but it sometimes returns None. Is there a smart way to find out an
unused colour or the least used colour in my image?

Additionally can PIL change a specified colour quickly. I'm guessing I might be
able to do it using the composite mechanism
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import Image
im0 = Image.open('trans.png')
im0.mode 'RGBA'
im0.getcolors() [(55367, (255, 1, 25, 255)), (24104, (24, 79, 235, 255)), (46529, (0, 0, 0, 0))]
im1 = Image.open('400px-Wiki_letter_w.svg.png')
im1.mode 'RGBA'
im1.getcolors()
im1.getcolors() is None True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top