Skip to main content

Resizes image origin to specified size.

Project description

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

Resizes image origin to specified size. Compatible with sorl-thumbnail.

Features

  • Tested on Django 2.2, 3.0, 3.1, 3.2, 4.0

  • Python 3 support

Installation

pip install django-resized

Configuration (optional)

settings.py

DJANGORESIZED_DEFAULT_SIZE = [1920, 1080]
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, 100], crop=['middle', 'center'], upload_to='whatever')
    image4 = ResizedImageField(size=[500, 300], quality=75, upload_to='whatever')
    image5 = ResizedImageField(size=[500, 300], upload_to='whatever', force_format='PNG')

Options

  • size - max width and height, for example [640, 480]

  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-resized-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_resized-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file django-resized-1.0.0.tar.gz.

File metadata

  • Download URL: django-resized-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for django-resized-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3e948b69829453b57850ef5b7015e78e639490f4a23c22a0abd42d45078d0ed2
MD5 ec8fd41844629fe8b36fd48cb9c1fcad
BLAKE2b-256 889af6d8bfe6d954edd2a263a37a6d13e0f957f3e44401553988ea6ab68f1ac4

See more details on using hashes here.

File details

Details for the file django_resized-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_resized-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for django_resized-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2e65221e839d46f07e0d2888d541736996eb674f1cdcd88440d05c56d3e4d3b
MD5 fb0e9b27f76b10179de929ccb848c4e1
BLAKE2b-256 8a8109316e42369046c752019650454a0c3fdfe3124e51432c1e6772d65601b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page