Skip to content

Commit da13514

Browse files
authored
Add documentation for dimension validators
1 parent 8532a42 commit da13514

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,30 @@ The default processor is `pictures.tasks.process_picture`. It takes a single
219219
argument, the `PictureFileFile` instance. You can use this to override the
220220
processor, should you need to do some custom processing.
221221

222+
### Validators
223+
224+
The library ships with validators to restrain image dimensions:
225+
226+
```python
227+
from django.db import models
228+
from pictures.models import PictureField
229+
from pictures.validators import MaxSizeValidator, MinSizeValidator
230+
231+
232+
class Profile(models.Model):
233+
picture = PictureField(
234+
upload_to="avatars",
235+
validators=[
236+
MinSizeValidator(400, 300), # At least 400x300 pixels
237+
MaxSizeValidator(4096, 4096), # At most 4096x4096 pixels
238+
]
239+
)
240+
241+
Use `None` to limit only one dimension: `MaxSizeValidator(2048, None)` limits only width.
242+
243+
> [!IMPORTANT]
244+
> These validators check image dimensions, not file size. Consider implementing HTTP request body size restrictions (e.g., in your web server or Django middleware) to prevent large file uploads.
245+
222246
## Migrations
223247

224248
Django doesn't support file field migrations, but we do.

0 commit comments

Comments
 (0)