Skip to content
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

create_captcha_image broken #63

Closed
peterthomassen opened this issue Jul 3, 2023 · 7 comments
Closed

create_captcha_image broken #63

peterthomassen opened this issue Jul 3, 2023 · 7 comments

Comments

@peterthomassen
Copy link

peterthomassen commented Jul 3, 2023

With the release of Pillow 10, the dependency of this module on Pillow (without version specifier) will now install Pillow 10.

This causes create_captcha_image to break:

  File "/usr/local/lib/python3.11/site-packages/captcha/image.py", line 45, in generate
    im = self.generate_image(chars)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/captcha/image.py", line 228, in generate_image
    im = self.create_captcha_image(chars, color, background)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/captcha/image.py", line 198, in create_captcha_image
    images.append(_draw_character(" "))
                  ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/captcha/image.py", line 165, in _draw_character
    w, h = draw.textsize(c, font=font)
           ^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'

A potential fix could be pinning to an older Pillow version (will likely cause other problems), or fixing the issue itself. https://pillow.readthedocs.io/en/stable/releasenotes/10.0.0.html#font-size-and-offset-methods hints at how to do that.

peterthomassen added a commit to desec-io/desec-stack that referenced this issue Jul 3, 2023
@MVARUNREDDY8203
Copy link

yes facing the same issue , how to fix?

@peterthomassen
Copy link
Author

A workaround is to pin the old Pillow version in your project's dependencies, as done here: desec-io/desec-stack@04e1470

While it works, it's suboptimal, because you will be stuck with that version of Pillow, which is no longer maintained.

@Serpensin
Copy link

Good thing that I always test my Code before publishing it. I use this lib in a CaptchaBot for Discord. And because this doesn't throw an error in the ide, it's pretty fucked to find the issue. It only showed in the logs (logging module) and in sentry.

@ThiefMaster
Copy link

@lepture a release fixing pillow 10 compatibility would be greatly appreciated. :)

Especially considering that security issues in Pillow aren't that rare, having to pin an outdated version of it is somewhat dangerous.

@ThiefMaster
Copy link

BTW I just gave it a quick try and there doesn't seem to be a drop-in replacement producing the same results...

This got pretty close though:

            left, top, right, bottom = draw.textbbox((0, 0), c, font=font)
            w = int((right - left)*1.7) or 1
            h = int((bottom - top)*1.7) or 1

I did not have a closer look on why I need to apply a factor or get really broken results, or why a whitespace has a width/height (don't remember which one) of 0...

@lepture
Copy link
Owner

lepture commented Jul 29, 2023

@peterthomassen This should be fixed by 0.5.0

@ThiefMaster
Copy link

Thanks, I can confirm that the fixed version works fine!

ilovechallenge added a commit to ilovechallenge/reCaptcha_Python that referenced this issue Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@ThiefMaster @lepture @peterthomassen @Serpensin @MVARUNREDDY8203 and others