Package: python-pil Version: 4.2.1-1 When using the text() function with the PIL ImageDraw module, if the text contains a blankline (IE: "\n\n"), PIL crashes.
However, if horizontal whitespace exists in the blank line, the module will not
error out. But if the blank line is excactly "\n\n", without any horizontal
whitespace, an exception is caught, and the ImageDraw module crashes with the
ImageDraw Draw.text() function.
Below is an interactive session in ipython(1). Notice the "\n\n" on input 19,
versus "\n" on input 7 and "\n \n" on input 18:
In [1]: from PIL import Image
In [2]: from PIL import ImageDraw
In [3]: from PIL import ImageFont
In [4]: from textwrap import TextWrapper
In [5]: fontfile =
"/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf"
In [6]: font = ImageFont.truetype(fontfile, 24)
In [7]: text = u'FOO\nBAR\nBAZ' # succeeds
In [8]: tw = TextWrapper()
In [9]: tw.width = 30
In [10]: num_lines = text.count("\n")
In [11]: height = 52 + (26 * num_lines) + 52
In [12]: background = Image.new("RGB", (500, max(160, height)), (255, 255,
255))
In [13]: img = Image.open("/home/aaron/src/ciphermonkey/images/banana.png")
In [14]: background.paste(img, (20, 10))
In [15]: draw = ImageDraw.Draw(background)
In [16]: draw.text((20, 52), text, (0, 0, 0), font=font)
In [17]: text = u'FOO\nBAR\n \nBAZ' # succeeds
In [18]: draw.text((20, 52), text, (0, 0, 0), font=font)
In [19]: text = u'FOO\nBAR\n\nBAZ' # fails
In [20]: draw.text((20, 52), text, (0, 0, 0), font=font)
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
<ipython-input-20-7219ebe64fdf> in <module>()
----> 1 draw.text((20, 52), text, (0, 0, 0), font=font)
/usr/lib/python2.7/dist-packages/PIL/ImageDraw.pyc in text(self, xy, text,
fill, font, anchor, *args, **kwargs)
207 if self._multiline_check(text):
208 return self.multiline_text(xy, text, fill, font, anchor,
--> 209 *args, **kwargs)
210 ink, fill = self._getink(fill)
211 if font is None:
/usr/lib/python2.7/dist-packages/PIL/ImageDraw.pyc in multiline_text(self,
xy, text, fill, font, anchor, spacing, align, direction, features)
231 line_spacing = self.textsize('A', font=font)[1] + spacing
232 for line in lines:
--> 233 line_width, line_height = self.textsize(line, font)
234 widths.append(line_width)
235 max_width = max(max_width, line_width)
/usr/lib/python2.7/dist-packages/PIL/ImageDraw.pyc in textsize(self, text,
font, spacing, direction, features)
258 if font is None:
259 font = self.getfont()
--> 260 return font.getsize(text, direction, features)
261
262 def multiline_textsize(self, text, font=None, spacing=4,
direction=None,
/usr/lib/python2.7/dist-packages/PIL/ImageFont.pyc in getsize(self, text,
direction, features)
154
155 def getsize(self, text, direction=None, features=None):
--> 156 size, offset = self.font.getsize(text, direction, features)
157 return (size[0] + offset[0], size[1] + offset[1])
158
SystemError: error return without exception set
--
. o . o . o . . o o . . . o .
. . o . o o o . o . o o . . o
o o o . o . . o o o o . o o o
signature.asc
Description: PGP signature

