mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-24 00:04:15 +00:00
captcha(-old).py: Support Pillow 10
getsize() function was removed in version 10 Bug: T354099 Change-Id: I019a5a89de4340d73a938c907c0a6f5cc22a659c
This commit is contained in:
parent
2b15ffbb94
commit
fbf8d90063
|
@ -46,6 +46,11 @@ except:
|
|||
|
||||
nonalpha = re.compile('[^a-z]') # regex to test for suitability of words
|
||||
|
||||
# Pillow 9.2 added getbbox to replace getsize, and getsize() was removed in Pillow 10
|
||||
# https://pillow.readthedocs.io/en/stable/releasenotes/10.0.0.html#font-size-and-offset-methods
|
||||
# We don't have a requirements.txt, and therefore don't declare any specific supported or min version...
|
||||
IMAGEFONT_HAS_GETBBOX = hasattr(ImageFont.ImageFont, "getbbox")
|
||||
|
||||
# Does X-axis wobbly copy, sandwiched between two rotates
|
||||
def wobbly_copy(src, wob, col, scale, ang):
|
||||
x, y = src.size
|
||||
|
@ -79,8 +84,13 @@ def gen_captcha(text, fontname, fontsize, file_name):
|
|||
fgcolor = 0xffffff
|
||||
# create a font object
|
||||
font = ImageFont.truetype(fontname,fontsize)
|
||||
|
||||
# determine dimensions of the text
|
||||
if IMAGEFONT_HAS_GETBBOX:
|
||||
dim = font.getbbox(text)[2:]
|
||||
else:
|
||||
dim = font.getsize(text)
|
||||
|
||||
# create a new image significantly larger that the text
|
||||
edge = max(dim[0], dim[1]) + 2*min(dim[0], dim[1])
|
||||
im = Image.new('RGB', (edge, edge), bgcolor)
|
||||
|
|
10
captcha.py
10
captcha.py
|
@ -47,6 +47,11 @@ except:
|
|||
|
||||
nonalpha = re.compile('[^a-z]') # regex to test for suitability of words
|
||||
|
||||
# Pillow 9.2 added getbbox to replace getsize, and getsize() was removed in Pillow 10
|
||||
# https://pillow.readthedocs.io/en/stable/releasenotes/10.0.0.html#font-size-and-offset-methods
|
||||
# We don't have a requirements.txt, and therefore don't declare any specific supported or min version...
|
||||
IMAGEFONT_HAS_GETBBOX = hasattr(ImageFont.ImageFont, "getbbox")
|
||||
|
||||
# Does X-axis wobbly copy, sandwiched between two rotates
|
||||
def wobbly_copy(src, wob, col, scale, ang):
|
||||
x, y = src.size
|
||||
|
@ -80,8 +85,13 @@ def gen_captcha(text, fontname, fontsize, file_name):
|
|||
fgcolor = 0xffffff
|
||||
# create a font object
|
||||
font = ImageFont.truetype(fontname,fontsize)
|
||||
|
||||
# determine dimensions of the text
|
||||
if IMAGEFONT_HAS_GETBBOX:
|
||||
dim = font.getbbox(text)[2:]
|
||||
else:
|
||||
dim = font.getsize(text)
|
||||
|
||||
# create a new image significantly larger that the text
|
||||
edge = max(dim[0], dim[1]) + 2*min(dim[0], dim[1])
|
||||
im = Image.new('RGB', (edge, edge), bgcolor)
|
||||
|
|
Loading…
Reference in a new issue