Index: /main/waeup.sirp/trunk/src/waeup/sirp/image/README.txt
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/image/README.txt	(revision 6065)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/image/README.txt	(revision 6066)
@@ -1,4 +1,4 @@
 waeup.sirp.image fields
-================
+=======================
 
 The image file widget is built on top of the ImageFile object::
@@ -106,4 +106,73 @@
   4
 
+`ImageFile` field
+-----------------
+
+As every other field (most of them are defined in :mod:`zope.schema`)
+`ImageFile` can be used in interfaces to tell, that the associated
+attribute should be -- an image file.
+
+The `ImageFile` field accepts only certain content types:
+
+  >>> from waeup.sirp.image.schema import ImageFile
+  >>> from zope.publisher.browser import TestRequest
+  >>> field = ImageFile(__name__='foo', title=u'Foo')
+  >>> field.validate('asd')
+  Traceback (most recent call last):
+  ...
+  WrongType: ('asd', <class 'waeup.sirp.image.image.WAeUPImageFile'>, 'foo')
+
+which means: `ImageFile` fields should better contain
+:class:`WAeUPImageFile` instances.
+
+We can store normal :class:`WAeUPImageFile` instances:
+
+  >>> field.validate(WAeUPImageFile('bar.jpg', 'data')) is None
+  True
+
+The `ImageFile` field supports min and max values:
+
+  >>> field = ImageFile(__name__='foo', title=u'Foo')
+  >>> hasattr(field, 'min_size')
+  True
+
+  >>> hasattr(field, 'max_size')
+  True
+
+By default both attributes are set to ``None``:
+
+  >>> field.min_size is field.max_size is None
+  True
+
+But we can set them:
+
+  >>> field = ImageFile(__name__='bar', title=u'Bar', 
+  ...                   min_size=5, max_size=12)
+
+and while these values are okay then:
+
+  >>> field.validate(
+  ...     WAeUPImageFile('bar.jpg', '123456789012')) is None
+  True
+
+  >>> field.validate(
+  ...     WAeUPImageFile('bar.jpg', '12345')) is None
+  True
+
+the following are not:
+
+  >>> field.validate(
+  ...     WAeUPImageFile('bar.jpg', '1234567890123'))
+  Traceback (most recent call last):
+  ...
+  TooBig: ('bar.jpg', '13 bytes (max: 12 bytes)')
+
+  >>> field.validate(
+  ...     WAeUPImageFile('bar.jpg', '1234'))
+  Traceback (most recent call last):
+  ...
+  TooSmall: ('bar.jpg', '4 bytes (min: 5 bytes)')
+
+
 Clean up::
 
Index: /main/waeup.sirp/trunk/src/waeup/sirp/image/schema.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/image/schema.py	(revision 6065)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/image/schema.py	(revision 6066)
@@ -23,13 +23,64 @@
 """
 from zope.interface import implements
+from zope.schema import MinMaxLen
+from zope.schema.interfaces import TooBig, TooSmall
 from hurry.file.schema import File
 from waeup.sirp.image.interfaces import IImageFile
 from waeup.sirp.image.image import WAeUPImageFile
 
-class ImageFile(File):
+class MinMaxSize(object):
+    """Expresses constraints on the size of an object.
+
+    The 'size' of an object is determined by its `size` method or
+    attribute. If an object has no such 'size' then it cannot be
+    validated by this mixin.
+
+    Please do not confuse `MinMaxSize` with `MinMaxLen`, for instance
+    supported by ordinary text fields. These test on ``len(obj)``
+    which is not necessary possible for file-like objects.
+
+    Therefore we distinguish 'size' from 'len' here.
+    """
+    min_size = None
+    max_size = None
+
+    def __init__(self, min_size=None, max_size=None, **kw):
+        self.min_size = min_size
+        self.max_size = max_size
+        super(MinMaxSize, self).__init__(**kw)
+
+    def _validate(self, value):
+        super(MinMaxSize, self)._validate(value)
+        if self.max_size is not None and value.size > self.max_size:
+            raise TooBig(
+                value.filename,
+                "%s bytes (max: %s bytes)" % (value.size, self.max_size))
+
+        if self.min_size is not None and value.size < self.min_size:
+            raise TooSmall(
+                value.filename,
+                "%s bytes (min: %s bytes)" % (value.size, self.min_size))
+
+    
+class ImageFile(MinMaxSize, File):
     """An image file field.
 
     Suitable for interfaces that wish to store image files in an
     attribute.
+
+    This field type supports `MinMaxSize` so that you can set
+    `min_size` or `max_size` for all `ImageFile` fields in your
+    interfaces like this:
+
+      class MyInterface(Interface):
+         image = ImageFile(
+             title = u'The image',
+             description = u'The nice image',
+             max_size = 1024 * 10,
+             )
+
+    to restrict the file size of stored images to 10 KBytes.
+
+    By default no such restriction is set.
     """
     implements(IImageFile)
