Django Simple Captcha image size

旧街凉风 提交于 2019-12-13 04:54:48

问题


How can I change captcha image size and text padding in image?

I read official docs and havn't found any of those.


回答1:


I have never used this app, but I've found in code something:

#captcha/views.py

def captcha_image(request, key, scale=1):
    #function goes here

So if you call captch_image with additional paramater scale, you can change the size. If you use urls for this app like

urlpatterns = patterns('captcha.views',
    url(r'image/(?P<key>\w+)/$', 'captcha_image', name='captcha-image', kwargs={'scale': 1}),

You can change scale parameter right in the line.

If you want to change proportions of dimensions, I think it is not supported, because

#captcha/views.captcha_image
...
size = font.getsize(text)
size = (size[0] * 2, int(size[1] * 1.2))
...

They are hardcoded in the function captcha_image. But you can replace the font.




回答2:


Maybe it would be an option to resize the captcha in your css (e.g. setting width/heigth to 150%)



来源:https://stackoverflow.com/questions/18849981/django-simple-captcha-image-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!