Created
April 19, 2012 20:36
-
-
Save BigglesZX/2423985 to your computer and use it in GitHub Desktop.
Easily output an email address as a PNG image in Django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image | |
import ImageFont, ImageDraw | |
from django.conf import settings | |
from django.http import HttpResponse | |
from os.path import join | |
def emailshield(request): | |
address = 'info@example.com' | |
# change the path below to a TTF file you want to use | |
font = ImageFont.truetype(join(settings.PROJECT_ROOT, 'static', 'Vera.ttf'), 14) | |
size = font.getsize(address) | |
im = Image.new('RGBA', size, (0, 0, 0, 0)) | |
draw = ImageDraw.Draw(im) | |
draw.text((0, 0), address, font=font, fill='black') | |
response = HttpResponse(mimetype='image/png') | |
im.save(response, "PNG") | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment