You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AttributeError: 'FreeTypeFont' object has no attribute 'getsize' (Pillow 10) #11040
in line 208: display_str_heights = [font.getsize(ds)[1] for ds in display_str_list]
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
This is caused by new version of Pillow (10) being installed by pip install tf-models-official which
removed the getsize function
Downgrading to Pillow 9.5 solved the problem
Reacted by Sidney Trzepacz, Thibaud Piccinali, vudangitwork, Matiur Rahman Minar, Jimmy Engelbrecht, lufei, QuantumAlchymist, ZususuZ, Mahziyar Esmaili, Justin and 114 more
Reacted by MagicSource, Patrycja, Jianqiu Chen, Aerialyn, xlnn and Xin Wang
Reacted by DL_researcher, 与尔不进, Gabriela Villagran, Oras Al-Kubaisi, bruce1408, Kosuke Takeuchi, Nick Hoo, Usama (PSEUDO), Md. Fahim Bin Amin, SacherTorte280 and 4 more
Reacted by DL_researcher, Akram Abduljabbar, bruce1408, Nick Hoo, Anton, Usama (PSEUDO), luke-lombardi, Md. Fahim Bin Amin, SacherTorte280, xlnn and 4 more
Reacted by DL_researcher, bruce1408, Nick Hoo, Usama (PSEUDO), Umar Oluwaleke, Jinpyo Joo, Md. Fahim Bin Amin, importTthis, SacherTorte280, xlnn and 4 more
We have noticed that the most recent version of the Pillow library has removed the getsize method. As a result, we are currently working on adapting our codebase to accommodate this change. In the meantime, to avoid encountering this error in your environment, we recommend installing version 9.5.0 of Pillow by using the command pip install Pillow<=9.5.0. This will allow you to continue your work smoothly until the necessary adjustments are made.
Hope you understand!
Thanks.
Reacted by Timothy, Thon de Boer, Bugrahan Donmez, eastnomoring, Suyash Dahale, Joost, Mirza Ahmed Baig, Map987, sangeun jo, Mateus Pereira and 3 more
Reacted by Felipe Mica, Timothy, johan-j-jo and xlnn
Reacted by Digital2Slave, Karan Deo Burnwal, Black Jack, Dulan Pabasara, empty-id, mech206117, Eric O. LEBIGOT (EOL), notudope, AlexWxW, Dmitriy Surkov and 19 more
Someone posted a quick fix for this issue over on Stack Overflow.
# old way using getsize()
# text_width, text_height = font.getsize(text)
# using pillow 10+
left, top, right, bottom = font.getbbox(text)
text_width = right - left
text_height = bottom - top
Activity
Sid220 commentedon Jul 10, 2023
Same issue
Digital2Slave commentedon Jul 11, 2023
pip install Pillow==9.5.0laxmareddyp commentedon Jul 11, 2023
Hi @PawZawDev,
We have noticed that the most recent version of the Pillow library has removed the
getsizemethod. As a result, we are currently working on adapting our codebase to accommodate this change. In the meantime, to avoid encountering this error in your environment, we recommend installingversion 9.5.0 of Pillowby using the commandpip install Pillow<=9.5.0. This will allow you to continue your work smoothly until the necessary adjustments are made.Hope you understand!
Thanks.
update dependencies
laxmareddyp commentedon Jul 24, 2023
Hi @PawZawDev,
A pull request that we submitted has been successfully merged.
Closing this as completed.
Thanks.
google-ml-butler commentedon Jul 24, 2023
Are you satisfied with the resolution of your issue?
Yes
No
tetrapod0 commentedon Aug 21, 2023
tested in 9.5.0
DeprecationWarning: getsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use getbbox or getlength instead.
IshuSinghSE commentedon Sep 26, 2023
now in pillow 10 you can use
Instead of
ImageFont.FreeTypeFont(fontfile, size=55, encoding="unic")andgetsize(string)use
ImageFont.truetype(fontfile, size=55, encoding="unic")andgetlength(string)fix: Change to Pillow version 9.5.0 or lower
BennisonDevadoss commentedon Dec 11, 2023
Here I have a question, what is the way to resolve this, without downgrade the version of the Pillow to 9.5.0
Pin Pillow to 9.5.0, see tensorflow/models#11040
weixianwei0129 commentedon Jul 30, 2024
fix(utils/plots.py): fix AttributeError: 'FreeTypeFont' object has no…
bighammer-link commentedon Nov 9, 2024
Thanks a lot! I sloved my problems with this way!!
commadelimited commentedon Aug 9, 2026
Someone posted a quick fix for this issue over on Stack Overflow.