From 675ce0b19373f4193b0a26046a70fedad8e4d8d7 Mon Sep 17 00:00:00 2001 From: Stefan Ott Date: Sat, 21 Sep 2024 00:25:46 +0200 Subject: [PATCH] Center characters vertically 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. --- captcha/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/captcha/views.py b/captcha/views.py index d2d7b80..5b5dd89 100644 --- a/captcha/views.py +++ b/captcha/views.py @@ -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