Good day, i am working on a project where i create a lot of PDFs and have been away for about half a year due to my work. Now I came back and should work a bit further on my project but I ran into some issues regarding deprecated functions in Pillow.
Here is the Function I have problems with:
def text(self, x, y, text, color, font_size, font_name=IRRELEVANT_FONT_REGULAR):
""" draws centralized text """
font = ImageFont.truetype(font_name, font_size) # which font to use
w, h = self.draw.textsize(text, font=font) # width, height of text for alignment
self.draw.text(((x - 0.5 * w), (y - 0.5 * h)), text, color, font=font, align="center") # draws text
As you can see, it uses the “textsize” method which is deprecated since version 9.3.0 of Pillow.
I am running into errors when creating the PDFs because of this function and do not know how to work around this to be honest since I did not write the code myself and am just expanding the code as the project gets bigger.
I tried to change the textsize method out with the textlength method, getsize method (which I found out is also deprecated), asked ChatGPT to write Code for me whithout the deprecated methods which did not work at all.
Does anybody know any workaround or replacement for the textsize method?