PIL palette problem on PIL-1.1.2/Python-2.1/Solaris 2.8

plakal at nospam-cs.wisc.edu plakal at nospam-cs.wisc.edu
Tue Jul 10 19:39:46 EDT 2001


plakal at nospam-cs.wisc.edu wrote:
> I'm trying to use PIL to draw a line
> graph on a pre-existing GIF template file.

> However, for some reason, no matter
> what palette index I specify as
> the ink, the lines I draw are all white
> (which happens to be the first color
> in the palette).

> Can anyone spot what I'm doing wrong?
> Code is at the end of the message.

> This is with PIL-1.1.2, Python 2.1,
> Solaris 2.8. Weirdly enough, the same
> code works fine on Linux (with Python 2.0
> and PIL-1.1.2).

	I finally figured out the problem.
	There seems to be a bug in the
	support code in PIL where
	_draw_lines() (in _imaging.c)
	passes a pointer to an int
        as the ink parameter to
        the ImagingDrawLine() function
        in libImaging which then treats it
	as a pointer to unsigned char.
        This returns zero on big-endian
	SPARC but returns the correct
        ink value on little-endian x86.

	I modified it myself to make
	it work for me but I assumed
	that this kind of stuff would
	be handled by the configure
	scripts since this kind of casting
	makes assumptions about endian-ness.

	Manoj



> PS: Remove nospam- from my email address to respond by mail.


> ------------------------------------------
> import Image, ImageDraw

> image = Image.open( "graph_template.gif" )  # -- 500x600 GIF, 67-color palette

> draw = ImageDraw.Draw( image )
> draw.setink(1)   # -- Orange-ish
> draw.line( [(52,550),(220,40)] )
> draw.setink(2)   # -- another shade of orange
> draw.line( [(220,40),(300,550)] )
> draw.ellipse( (52,40,300,550) )

> image.save( "graph.gif" )
> ------------------------------------------




More information about the Python-list mailing list