Skip to content

Commit

Permalink
Center characters vertically
Browse files Browse the repository at this point in the history
Currently math challenges look a bit weird because the math operators
are smaller than the numbers and everything is aligned at the top of the
image.

This change moves all characters to the vertical center, making math
challenges a bit nicer to look at.
  • Loading branch information
cockroach committed Sep 20, 2024
1 parent 153cfd9 commit 675ce0b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions captcha/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ def captcha_image(request, key, scale=1):
charimage = charimage.crop(charimage.getbbox())
maskimage = Image.new("L", size)

yoffset = (size[1] - charimage.size[1]) // 2
maskimage.paste(
charimage,
(
xpos,
DISTANCE_FROM_TOP,
yoffset,
xpos + charimage.size[0],
DISTANCE_FROM_TOP + charimage.size[1],
charimage.size[1] + yoffset,
),
)
size = maskimage.size
Expand Down

0 comments on commit 675ce0b

Please sign in to comment.