Skip to main content
https://github.com/un1t/django-resized/actions/workflows/python-app.yml/badge.svg

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

Release files for django-resized 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-resized 1.0.3
File Size Uploaded
django_resized-1.0.3.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-resized 1.0.3
File Interpreter ABI Platform
django_resized-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / django_resized-1.0.3.tar.gz

Download URL django_resized-1.0.3.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c199f2b6e315816753df3a7a3889b923d3b73ce89fa16af93761cf2ea9bac4f7
BLAKE2b-256 checksum
How to use checksums
fcaa5e83b3dec9c1ec7d336c86e83bbc93674cd4fc125879a827b932a0ec25c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / django_resized-1.0.3-py3-none-any.whl

Download URL django_resized-1.0.3-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5b0cf0d1db4f8db43362eef121d94d63487e2bff7a59c45046a1420788db353
BLAKE2b-256 checksum
How to use checksums
38ac3495743e9923a3b79a929782f63db7acd606dc94c15c296487ef6d015717
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.11

1 release file

0.3.10

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page