CookBook - Validate an image size
django version : 0.91
To check the height and width of an image uploaded via your form, you can implement this method into your view.py or custom manipulator.
You need PIL http://www.pythonware.com/products/pil/ to be installed.
Code
Here we check that the image is 100*100 pixels.
import Image import StringIO def isValidSize(field_data, all_data): im = Image.open(StringIO.StringIO(field_data["content"])) if im.size != (100,100): raise validators.ValidationError, "The image size does not match 100*100"
Last modified
19 years ago
Last modified on Feb 27, 2006, 4:56:51 AM
Note:
See TracWiki
for help on using the wiki.