We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageDraw.textsize() does not return correct textsize for truetype fonts. The return value does not include offset.
ImageDraw.textsize()
textsize
So I have to adjust offset using FreeTypeFont.getoffset() to get correct textsize.
FreeTypeFont.getoffset()
from PIL import Image, ImageDraw, ImageFont image = Image.new('RGB', (512, 256), (255, 255, 255)) drawer = ImageDraw.Draw(image) font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeSerif.ttf', 32) # drawing text STRING = 'Hello, python language!' drawer.text((10, 10), STRING, fill='black', font=font) # drawing rectangle surrounding text size = drawer.textsize(STRING, font=font) offset = font.getoffset(STRING) drawer.rectangle((10, 10, 10 + size[0] + offset[0], 10 + size[1] + offset[1]), outline='black') image.save('example.png', 'PNG')
is this correct way?
And, I think ImageDraw.textsize() should return textsize including offset.
The text was updated successfully, but these errors were encountered:
This seems to keep happening: https://stackoverflow.com/questions/59008322/pillow-imagedraw-text-coordinates-to-center/59008967#59008967
Sorry, something went wrong.
Had to do a hacky workaround aswell
ImageDraw.textsize() was been removed in Pillow 10.0.0. See https://pillow.readthedocs.io/en/stable/deprecations.html#font-size-and-offset-methods for more information.
If you still have a problem, please open a new issue so that it can be discussed further.
Successfully merging a pull request may close this issue.
ImageDraw.textsize()
does not return correcttextsize
for truetype fonts.The return value does not include offset.
So I have to adjust offset using
FreeTypeFont.getoffset()
to get correcttextsize
.is this correct way?
And, I think
ImageDraw.textsize()
should returntextsize
including offset.The text was updated successfully, but these errors were encountered: