471,350 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

PIL image.getcolors

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')
[(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.getcolors() is None

Robin Becker

Nov 29 '07 #1
0 1192

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Pierre Tremblay | last post: by
3 posts views Thread by dave | last post: by
2 posts views Thread by Tjerk | last post: by
8 posts views Thread by Jef Driesen | last post: by
15 posts views Thread by Anand Ganesh | last post: by
7 posts views Thread by lgbjr | last post: by
1 post views Thread by oruccim | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.