New issue
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
Pillow dreprecation warning about ImageFont.getsize #163
Comments
Should we use ImageFont.getbbox or ImageFont.getlength here? |
I think you should use |
Author of the This is the code in question, yes? python-barcode/barcode/writer.py Lines 437 to 448 in 77c902f
And it seems you are trying to align text by the bottom-middle point? Perhaps (untested): def _paint_text(self, xpos, ypos):
font_size = int(mm2px(pt2mm(self.font_size), self.dpi))
font = ImageFont.truetype(self.font_path, font_size)
for subtext in self.text.split("\n"):
pos = (
mm2px(xpos, self.dpi),
mm2px(ypos, self.dpi),
)
self._draw.text(pos, subtext, font=font, fill=self.foreground, anchor="ms")
ypos += pt2mm(self.font_size) / 2 + self.text_line_distance |
In general, |
That makes sense. This deprecation is a good opportunity to polish this a bit and align text the way it should be done. @brvoisin Are you interested in writing a PR for this? |
Thanks for chiming in, @nulano ! |
python-barcode/barcode/writer.py:441: DeprecationWarning: getsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use getbbox or getlength instead. width, height = font.getsize(subtext) `ImageFont.getsize` is deprecated since the version 9.2 of Pillow. We use anchor instead of computing the right position to have an aligned text. It is related to the issue WhyNotHugo#163. The solution was suggested by nulano (contributor of Pillow).
Pillow 10.0.0 has been released: https://pypi.org/project/Pillow/10.0.0/ |
@cedk What fix? Pillow is unpinned, so 10.0.0 should work without any issues. |
This one otherwise the last release of python-barcode crashes with Pillow 10.0.0. |
For the record, our test suite is failing like this https://foss.heptapod.net/tryton/tryton/-/jobs/1990306 because the release 0.14.0 is missing this compatibility fix with Pillow 10.0.0. |
python-barcode 0.15.1 is out |
in new For More Info see their Doc: pillow documentation or you can use |
Hello!
Pillow 9.2.0 is installed in my virtualenv and when I use python-barcode there is a deprecation warning about the method
ImageFont.getsize
.Since the version 9.2,
getsize
is deprecated and replaced bygetlength
. See the PR python-pillow/Pillow#6381.The text was updated successfully, but these errors were encountered: