IOError: unknown freetype error - occurs with large amounts of text
Andy Theuninck <[email protected]> Thu, 13 Jun 2013 14:09:29 -0500
| Newsgroups | gmane.comp.python.image |
|---|---|
| Message-ID | <CAHeUxT4hdquYRNnMBvxSZq-zGXJidpza1jrqbGh4hjELuDf68A@mail.gmail.com> |
--===============1602842199==
Content-Type: multipart/alternative; boundary=047d7bf0ca02a03ffe04df0dde8c
--047d7bf0ca02a03ffe04df0dde8c
Content-Type: text/plain; charset=ISO-8859-1
I have a method that takes a list of strings, a width, and a height and
draws them using PIL. For small to medium lists this works perfectly. For
large lists it crashes with this rather opaque exception:
Traceback (most recent call last):
File "square-code.py", line 252, in <module>
obj.main(sys.argv[1:])
File "square-code.py", line 98, in main
self.render(lines, self.width, self.height)
File "square-code.py", line 109, in render
draw.text((x,y),line,font=font,fill=(0,0,0))
File "/usr/lib64/python2.6/site-packages/PIL/ImageDraw.py", line 263, in
text
mask, offset = font.getmask2(text, self.fontmode)
File "/usr/lib64/python2.6/site-packages/PIL/ImageFont.py", line 151, in
getmask2
self.font.render(text, im.id, mode=="1")
IOError: unknown freetype error
I've tried a couple different fonts and that doesn't make much difference.
Image size also doesn't appear to matter. For example, with a 2600x2000
image if I write ~250 lines with ~650 characters each it works fine (font
size 6). If I try to write ~950 lines with ~1300 characters each (font size
2) I get the crash above. I'd appreciate any insight into what might be
going wrong, things I can do differently, or how to debug the problem. My
method looks like this:
def render(self, lines, width, height):
im = Image.new('RGB',(width,height),(0xff,0xff,0xff))
draw = ImageDraw.Draw(im)
font = self.get_font(self.font_size)
x = 0
y = 0
for line in lines:
draw.text((x,y),line,font=font,fill=(0,0,0))
y += font.getsize(line)[1]
if os.path.splitext(self.ofile)[1] == '': self.ofile +=
".png"
im.save(self.ofile)
Python 2.6, PIL 1.1.7
--047d7bf0ca02a03ffe04df0dde8c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div>I have a method that takes a list of strings, a =
width, and a height and draws them using PIL. For small to medium lists thi=
s works perfectly. For large lists it crashes with this rather opaque excep=
tion:<br>
<br>Traceback (most recent call last):<br>=A0 File "square-code.py&quo=
t;, line 252, in <module><br>=A0=A0=A0 obj.main(sys.argv[1:])<br>=A0 =
File "square-code.py", line 98, in main<br>=A0=A0=A0 self.render(=
lines, self.width, self.height)<br>
=A0 File "square-code.py", line 109, in render<br>=A0=A0=A0 draw.=
text((x,y),line,font=3Dfont,fill=3D(0,0,0))<br>=A0 File "/usr/lib64/py=
thon2.6/site-packages/PIL/ImageDraw.py", line 263, in text<br>=A0=A0=
=A0 mask, offset =3D font.getmask2(text, self.fontmode)<br>
=A0 File "/usr/lib64/python2.6/site-packages/PIL/ImageFont.py", l=
ine 151, in getmask2<br>=A0=A0=A0 self.font.render(text, <a href=3D"http://=
im.id">im.id</a>, mode=3D=3D"1")<br>IOError: unknown freetype err=
or<br><br>
</div>I've tried a couple different fonts and that doesn't make muc=
h difference. Image size also doesn't appear to matter. For example, wi=
th a 2600x2000 image if I write ~250 lines with ~650 characters each it wor=
ks fine (font size 6). If I try to write ~950 lines with ~1300 characters e=
ach (font size 2) I get the crash above. I'd appreciate any insight int=
o what might be going wrong, things I can do differently, or how to debug t=
he problem. My method looks like this:<br>
<br>=A0=A0=A0=A0=A0=A0=A0 def render(self, lines, width, height):<br>=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 im =3D Image.new('RGB',(wid=
th,height),(0xff,0xff,0xff))<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0 draw =3D ImageDraw.Draw(im)<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0 font =3D self.get_font(self.font_size)<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 x =3D 0<br>=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0 y =3D 0<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0 for line in lines:<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0 draw.text((x,y),line,font=3Dfont,fill=3D(0,0,0)=
)<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
y +=3D font.getsize(line)[1]<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0 if os.path.splitext(self.ofile)[1] =3D=3D '': self.ofile +=3D &=
quot;.png"<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 im.save(self.ofile)<br><br></=
div>Python 2.6, PIL 1.1.7<br></div>
--047d7bf0ca02a03ffe04df0dde8c--
--===============1602842199==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Image-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/image-sig
--===============1602842199==--