| 1 | = CookBook - Validate an image height and width = |
| 2 | To check the height and width of an image uploaded via your form, you |
| 3 | can implement this method into your view.py or custom manipulator. |
| 4 | You need PIL [http://www.pythonware.com/products/pil/] to be installed. |
| 5 | == Code == |
| 6 | Here we check that the image is 100*100 pixels. |
| 7 | {{{ |
| 8 | import Image |
| 9 | import StringIO |
| 10 | |
| 11 | def isValideSize(field_data, all_data): |
| 12 | im = Image.open(StringIO.StringIO(field_data["content"])) |
| 13 | if im.size != (100,100): |
| 14 | raise validators.ValidationError, "The image size does not match 100*100 " |
| 15 | }}} |