[Image-SIG] ImageFont problems

Richard Jones richard.jones@bom.gov.au
Fri, 15 May 1998 07:26:43 +0000

Hey all,

    I've just started using the ImageFont facility of PIL, and have run 
into a 'bug' in the cropping code (Crop.c) of libImaging. I narrowed the 
problem down to a general problem with cropping to:

>>> import Image
>>> im = Image.new('1',(800,9))
>>> im.im.crop((300,0,310,6))
Traceback (innermost last):
  File "<stdin>", line 1, in ?
SystemError: NULL result without error in call_object

    Basically, I had to change the code in Crop.c to:

    /* Determine which region to copy */
    xoff = yoff = 0;
    if (x0 < 0)
        xsize += x0, xoff = -x0, x0 = 0;
    if (xsize > imOut->xsize)
        xsize = imOut->xsize;
    if (y0 < 0)
        ysize += y0, yoff = -y0, y0 = 0;
    if (ysize > imOut->ysize)
        ysize = imOut->ysize;

    Now, that seems to work - it doesn't generate a SystemError any more. 
The xoff and yoff values don't seem to be used anyway. What should the 
behaviour be if out of bounds values are passed to crop()?

    But then I try:

>>> import Image, ImageDraw, ImageFont
>>> im=Image.new('1',(300,200))
>>> d=ImageDraw.ImageDraw(im)
>>> f=ImageFont.load('/home/rtj/lib/BDF/luBS24.pil')
>>> d.setfont(f)
>>> d.text((10,10), 'hello world')
>>> im.show()

    and I get a blank image. I I go further and try:

>>> f.getmask('hello world').show()

    I get the text. What am I doing wrong?


Richard Jones,  Satellite Section at the Bureau of Meteorology, Australia.
                                               Work phone: +61-3-9669-4539