Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Resize and crop an image to fit the specified size.

Project description

Resize and Crop

Description

Resize and crop an image to fit the specified size.

Installation

pip install resize-and-crop

or

pipenv install resize-and-crop

Methods

  1. resize_and_crop(path, size, crop_origin) - Resize the image located at path, into the size specified, cropping the image starting at the crop_origin.
  2. resized_image_file(image_field, format, dimensions, crop_origin) - Returns a new image file that has the resized image. Can be used to save to a Django ImageField.

Usage

from resize_and_crop import resize_and_crop

image = resize_and_crop("/path/to/image", (200,200), "middle")
from django.db import models
from resize_and_crop.utils import resized_image_file

class ExampleModel(models.Model):
	image = models.ImageField(upload_to="images/")
	thumbnail = models.ImageField(upload_to="thumbnails/")

	def save(self, *args, **kwargs):
		if self.image and not self.thumbnail:
			self.thumbnail = resized_image_file(
				self.image,
				"jpeg",
				(200, 200),
			)
		return super().save(*args, **kwargs)

Project details


Download files

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

Files for resize-and-crop, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size resize_and_crop-0.1.1-py3-none-any.whl (3.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size resize_and_crop-0.1.1.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page