[IMAGE-SIG] SETINK - font colors on stamped strings

Daniel Michelson Daniel.Michelson@smhi.se
Mon, 22 Sep 1997 09:49:07 +0200


Hej,

> I know my question might be obvious and so might be the answer, but wha=
t
> is the way to set the font color that will be stamped onto an image to,=

> lets say, pure red?
> i have got to white, black and some weird colors with the setink
> function but i havent quite understood the one number color value.
> is there any literature about this matter?

The functionality you're looking for is undocumented. So, the answer to
your question is not obvious. You should be able to define your own
palette and then draw your text using setink method which looks up a
purely red color in the palette. PIL palettes are binary strings with
768 members with the format rgbrgbrgb...

I'm just improvising here but the following should be possible to do:

# create a palette string "palstr" somehow (not covered here)
this =3D Image.new("1", (xsize, ysize), 255) # initiate a white image
font =3D ImageFont.load(FONT_PATH + "lubB18.pil") # choose a font
this.palette =3D ImagePalette.raw('RGB', palstr)
legend.palette.data =3D palstr
draw =3D ImageDraw.ImageDraw(this)
draw.setfont(font)
draw.setink(5) # make sure palstr[14],palstr[15],palstr[16]=3D255,0,0
               # for pure red.
draw.text((xcoord,ycoord), textstring) # heavy on memory use...
del draw

I hope this helps.

Can you please clarify what you mean by "center a string to be stamped
onto an image"?

best, -d

+------------------+--------------------------------------------------+
|                  | Daniel B. Michelson                              |
| /\ |\  /| |  | | | Swedish Meteorological and Hydrological Institute|
| \  | \/ | |__| | | S-601 76 Norrk=F6ping, Sweden                      |=

|  \ |    | |  | | | Telephone: +46 11 - 15 84 94                     |
| \/ |    | |  | | | Telefax:   +46 11 - 17 02 07                     |
|                  | Internet:  Daniel.Michelson@smhi.se              |
+------------------+--------------------------------------------------+

_______________
IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
_______________