CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=e401e48ab58d629ffe734740; HttpOnly; Path=/; Secure
set-cookie: trac_session=10cae67d8ca00d96efe1a97b; expires=Tue, 21 Oct 2025 05:27:33 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 23 Jul 2025 05:27:33 GMT
x-served-by: cache-fra-etou8220022-FRA, cache-bom-vanm7210080-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753248454.692016,VS0,VE267
vary: Accept-Encoding
TextImageView – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
Generating Dynamic Text Images
Taken from Jacobian.org https://www.jacobian.org/2006/jun/30/improved-text-image-view/
import md5 from django.conf import settings from django.http import (HttpResponse, HttpResponseNotModified, HTTPResponseForbidden) import Image, ImageFont, ImageDraw def view_header(request, fontalias): try: fontfile = settings.DYNAMIC_FONT_ALIASES[fontalias] except: return HttpResponseForbidden("font alias not supported") header = request.GET.get('text', 'Hello world') etag = md5.new(header + fontalias).hexdigest() if request.META.get("HTTP_IF_NONE_MATCH") == etag: return HttpResponseNotModified() imf = ImageFont.truetype(fontfile, 20) size = imf.getsize(header) im = Image.new("RGB", size) draw = ImageDraw.Draw(im) draw.text((0, 0), header, font=imf) response = HTTPResponse(mimetype="image/png") im.save(response, "PNG") response["e-tag"] = etag return response
Last modified
16 years ago
Last modified on Dec 23, 2009, 1:42:21 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.