Skip to content

Commit

Permalink
Add a default font
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Nov 27, 2014
1 parent 1e6cf58 commit 37989eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,3 +1,4 @@
include LICENSE
include README.rst
recursive-include captcha/data *.wav
recursive-include captcha/data *.ttf
Binary file added captcha/data/DroidSansMono.ttf
Binary file not shown.
20 changes: 7 additions & 13 deletions captcha/image.py
Expand Up @@ -6,6 +6,7 @@
Generate Image CAPTCHAs, just the normal image CAPTCHAs you are using.
"""

import os
import random
from PIL import Image
from PIL import ImageFilter
Expand All @@ -17,9 +18,13 @@
except ImportError:
wheezy_captcha = None

DATA_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
DEFAULT_FONTS = [os.path.join(DATA_DIR, 'DroidSansMono.ttf')]


class _Captcha(object):
def generate(self, chars):
"""Generate an Image Captcha of the given characters."""
im = self.generate_image(chars)
out = BytesIO()
im.save(out, format='png')
Expand All @@ -35,7 +40,7 @@ class WheezyCaptcha(_Captcha):
def __init__(self, width=200, height=75, fonts=None):
self._width = width
self._height = height
self._fonts = fonts
self._fonts = fonts or DEFAULT_FONTS

def generate_image(self, chars):
text_drawings = [
Expand Down Expand Up @@ -66,7 +71,7 @@ class ImageCaptcha(_Captcha):
def __init__(self, width=160, height=60, fonts=None):
self._width = width
self._height = height
self._fonts = fonts
self._fonts = fonts or DEFAULT_FONTS
self._truefonts = []

@property
Expand Down Expand Up @@ -169,17 +174,6 @@ def generate_image(self, chars):
im = im.filter(ImageFilter.SMOOTH)
return im

def generate(self, chars):
im = self.generate_image(chars)
out = BytesIO()
im.save(out, format='png')
out.seek(0)
return out

def write(self, chars, output):
im = self.generate_image(chars)
return im.save(output, format='png')


def random_color(start, end, opacity=None):
red = random.randint(start, end)
Expand Down

0 comments on commit 37989eb

Please sign in to comment.