Django-Resized

raw JSON →
1.0.3 verified Fri May 01 auth: no python

Automatically resize image uploads in Django to a specified size. Current version 1.0.3, released sporadically. Lightweight replacement for django-imagekit for simple resize-on-upload scenarios.

pip install django-resized
error ImportError: cannot import name 'ResizedImageField' from 'django_resized.forms'
cause In version 1.0, the module structure changed; 'forms' submodule removed.
fix
Use 'from django_resized import ResizedImageField'.
error OSError: cannot write mode RGBA as JPEG
cause Uploaded image has transparency (RGBA) but output format is JPEG, which doesn't support alpha.
fix
Set 'quality' parameter or ensure uploaded images don't have alpha, or use a library that handles conversion.
breaking Import path changed in v1.0: from 'django_resized.forms' to 'django_resized'.
fix Use 'from django_resized import ResizedImageField' instead of 'from django_resized.forms import ResizedImageField'.
gotcha 'crop' parameter requires a list of two strings: ['top','bottom'] or ['left','right']; using a single string or invalid values silently fails.
fix Always pass a list with exactly two valid values, e.g., crop=['middle', 'center'].
gotcha ResizedImageField does not preserve original image; the uploaded file is replaced by the resized version.
fix If you need both original and resized, use a separate field for original or use a different library like django-imagekit.

Define a model with a ResizedImageField that automatically resizes images to 800x600, cropping from the center.

from django.db import models
from django_resized import ResizedImageField

class MyModel(models.Model):
    image = ResizedImageField(size=[800, 600], crop=['middle', 'center'], upload_to='uploads/')