mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Fix issue #382: TypeError with TransposedFont's getsize()
When getting the size of text with a TransposedFont it was failing: File "/usr/local/lib/python2.7/site-packages/PIL/ImageDraw.py", line 281, in textsize return font.getsize(text) File "/usr/local/lib/python2.7/site-packages/PIL/ImageFont.py", line 189, in getsize w, h = self.font.getsize(text)[0] TypeError: 'int' object is not iterable This is because self.font.getsize(text) returns a (w, h) tuple. To fix, remove the [0]. Test cases have been created in test_imagefont.py: test_rotated_transposed_font() test_unrotated_transposed_font() Both fail before the fix, both pass with the fix. Furthermore, the code I'm using this from ( https://github.com/mattdeboard/word_cloud ) now works as expected and creates a word cloud similar to the ones that PIL created.
This commit is contained in:
parent
c91bd27eec
commit
92507e5d0a
|
@ -171,7 +171,7 @@ class TransposedFont:
|
|||
self.orientation = orientation # any 'transpose' argument, or None
|
||||
|
||||
def getsize(self, text):
|
||||
w, h = self.font.getsize(text)[0]
|
||||
w, h = self.font.getsize(text)
|
||||
if self.orientation in (Image.ROTATE_90, Image.ROTATE_270):
|
||||
return h, w
|
||||
return w, h
|
||||
|
|
Loading…
Reference in New Issue
Block a user