Resizes image origin to specified size.
Project description
Resizes image origin to specified size. Compatible with sorl-thumbnail. Inherits from ImageField.
Features
Tested on Django 3.2, 4.0, 4.1, 4.2, 5.0, 5.1
Installation
pip install django-resized
Configuration (optional)
settings.py
DJANGORESIZED_DEFAULT_SIZE = [1920, 1080]
DJANGORESIZED_DEFAULT_SCALE = 0.5
DJANGORESIZED_DEFAULT_QUALITY = 75
DJANGORESIZED_DEFAULT_KEEP_META = True
DJANGORESIZED_DEFAULT_FORCE_FORMAT = 'JPEG'
DJANGORESIZED_DEFAULT_FORMAT_EXTENSIONS = {'JPEG': ".jpg"}
DJANGORESIZED_DEFAULT_NORMALIZE_ROTATION = True
Usage
models.py
from django_resized import ResizedImageField
class MyModel(models.Model):
...
image1 = ResizedImageField(size=[500, 300], upload_to='whatever')
image2 = ResizedImageField(size=[100, 100], crop=['top', 'left'], upload_to='whatever')
image3 = ResizedImageField(size=[100, 150], crop=['middle', 'center'], upload_to='whatever')
image4 = ResizedImageField(scale=0.5, quality=75, upload_to='whatever')
image5 = ResizedImageField(size=None, upload_to='whatever', force_format='PNG')
image6 = ResizedImageField(size=[100, None], upload_to='whatever')
Options
size - max width and height, for example [640, 480]. If a dimension is None, it will resized using the other value and maintains the ratio of the image. If size is None, the original size of the image will be kept.
scale - a float, if not None, which will rescale the image after the image has been resized.
crop - resize and crop. [‘top’, ‘left’] - top left corner, [‘middle’, ‘center’] is center cropping, [‘bottom’, ‘right’] - crop right bottom corner.
quality - quality of resized image 0..100, -1 means default
keep_meta - keep EXIF and other meta data, default True
force_format - force the format of the resized image, available formats are the one supported by pillow, default to None
How to run tests
pip install tox
tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_resized-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b0cf0d1db4f8db43362eef121d94d63487e2bff7a59c45046a1420788db353 |
|
MD5 | 3d1bed84ec5811c820f5dd991aaeb634 |
|
BLAKE2b-256 | 38ac3495743e9923a3b79a929782f63db7acd606dc94c15c296487ef6d015717 |