Professional Documents
Culture Documents
Resizeimagefield (Extension of Removableimagefield) : Wim Feijen
Resizeimagefield (Extension of Removableimagefield) : Wim Feijen
(extension of
RemovableImageField)
Wim Feijen
Go2People
wim@go2people.nl
1
What?
Replacement for django's ImageField.
Benefits:
•
Creation of thumbnail and scaled image
•
Extends image upload form.
Easy to use:
replace ImageField by ResizeImageField.
No further changes.
2
3
4
5
Usage:
add resize_image.py to your app
add resize_filters.py to your templatetags
in settings.py, set a PHOTO_DIR, f.e. photos/original
•
scaled images will be stored in photos/scaled
•
thumbnails will be stored in photos/thumb
in models.py:
•
from settings import PHOTO_DIR
•
from resize_image import ResizeImageField
•
photo = ResizeImageField(upload_to=PHOTO_DIR, blank=True,
verbose_name=_('Foto'))
6
Access from templates:
{% load resize_filters %}
{{ address.photo.url|thumb }} or:
{{ address.photo.url|scaled }}
7
Defaults
Scaled images are: 200x200 pixels
Thumbnails: 50x50 pixels by default
Override default behaviour in settings
8
Credits
Credits to tomZ for python snippet 636:
"Updated Filefield / ImageField with a
delete checkbox"
9
Workspace for rent
deskspace: 2.8 x 0.75 meters
Keizersgracht 8:
magnificent view Keizersgracht and Brouwersgracht
10 min. walk to Amsterdam Central Station
meeting room
office shared with fellow Djangonauts
295 euro / month excl. VAT
10
Questions?
11
Source code
http://github.com/wimfeijen/
ResizeImageField
12