[Image-SIG] How to specify the color of a text

cafeeee cafeeee at gmail.com
Tue Apr 29 06:09:05 CEST 2008


I failed to specify the color of the text while drawing a text into an
image:

>>> import Image, ImageDraw, ImageColor, ImageFont
>>> image = Image.open("a.gif")
>>> draw = ImageDraw.Draw(image)
>>> font = ImageFont.truetype("arial.ttf", 15)
>>> color = "blue"
>>> draw.text((10, 10), "HELLO", fill=color, font=font)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Program Files\Python25\Lib\site-packages\PIL\ImageDraw.py", line
256, in text
    ink, fill = self._getink(fill)
  File "D:\Program Files\Python25\Lib\site-packages\PIL\ImageDraw.py", line
145, in _getink
    ink = self.palette.getcolor(ink)
  File "D:\Program Files\Python25\Lib\site-packages\PIL\ImagePalette.py",
line 62, in getcolor
    self.palette = map(int, self.palette)
ValueError: invalid literal for int() with base 10: ''

Any comment are appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20080429/809d5e57/attachment.htm>


More information about the Image-SIG mailing list