diff options
Diffstat (limited to 'jm2l/captcha.py')
-rw-r--r-- | jm2l/captcha.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/jm2l/captcha.py b/jm2l/captcha.py index 65ab5db..521d726 100644 --- a/jm2l/captcha.py +++ b/jm2l/captcha.py @@ -3,7 +3,7 @@ import random from PIL import Image, ImageDraw, ImageFont, ImageFilter -import StringIO +from io import BytesIO import math from pyramid.view import view_config from .words import TabMots @@ -48,17 +48,17 @@ class _PyCaptcha_WarpBase(object): def render(self, image): r = self.resolution - xPoints = image.size[0] / r + 2 - yPoints = image.size[1] / r + 2 + xPoints = image.size[0] // r + 2 + yPoints = image.size[1] // r + 2 f = self.get_transform(image) # Create a list of arrays with transformed points xRows = [] yRows = [] - for j in xrange(yPoints): + for j in range(yPoints): xRow = [] yRow = [] - for i in xrange(xPoints): + for i in range(xPoints): x, y = f(i*r, j*r) # Clamp the edges so we don't get black undefined areas @@ -73,8 +73,8 @@ class _PyCaptcha_WarpBase(object): # Create the mesh list, with a transformation for # each square between points on the grid mesh = [] - for j in xrange(yPoints-1): - for i in xrange(xPoints-1): + for j in range(yPoints-1): + for i in range(xPoints-1): mesh.append(( # Destination rectangle (i*r, j*r, @@ -124,7 +124,7 @@ def DoCaptcha(request): # Choose a word for captcha text = random.choice(TabMots) Xt, Yt = font.getsize(text) - OrX, OrY = (ImgSize[0]-Xt)/2, (ImgSize[1]-Yt)/2 + OrX, OrY = (ImgSize[0]-Xt)//2, (ImgSize[1]-Yt)//2 draw.text((OrX, OrY), text, font=font, fill="#000000") # Apply a Blur # WorkImg=WorkImg.filter(ImageFilter.BLUR) @@ -145,7 +145,7 @@ def DoCaptcha(request): # Save Result request.session['Captcha'] = text #session.save() - ImgHandle = StringIO.StringIO() + ImgHandle = BytesIO() WorkImg.save(ImgHandle,'png') ImgHandle.seek(0) return Response(app_iter=ImgHandle, content_type = 'image/png') |