django-croppy 
django-croppy enables creating custom crops of images by specifying a name, coordinates, width and height of the crop.
django-croppy provides a custom model field responsible for creating and deleting crops. Crops are stored as serialized JSON data on the same model as the image field via django-jsonfield.
django-croppy is useful if you want to manually curate the crop size and location instead of relying on generic cropping like django-imagekit provides.
django-croppy makes use of image processors provided by django-imagekit.
Usage
First, create your model with a crop field. You can specify a custom location where to save crops to with the upload_to parameter:
from django.db import models
from croppy.fields import CropField
def upload_to(instance, filename, crop_name):
"""
Default function to specify a location to save crops to.
:param instance: The model instance this crop field belongs to.
:param filename: The image's filename this crop field operates on.
:param crop_name: The crop name used when :attr:`CropFieldDescriptor.crop` was
called.
"""
filename, ext = os.path.splitext(os.path.split(filename)[-1])
return os.path.join('crops', u'%s-%s%s' % (filename, crop_name, ext))
class Image(models.Model):
image = models.ImageField()
crops = CropField('image', upload_to = upload_to)
The created crops field allows you to create, delete and inspect crops.
$ git clone git@github.com:caffeinehit/django-croppy.git
$ cd django-croppy
$ python manage.py syncdb
...
$ python manage.py shell
...
>>> from tests.app import tests
>>> image = tests.get_image('test.tiff')
>>> image
<Image: Image object>
>>> image.image
<ImageFieldFile: images/test.tiff>
>>> image.image.path
u'/home/alen/projects/django-croppy/tests/test-media/images/test.tiff'
>>> # Inspect the crop data
>>> image.crops.data
{}
>>> # Create a new crop called 'rect' at position 0/0
>>> # with a width of 100px and a height of 50px
>>> image.crops.create('rect', (0, 0, 100, 50))
>>> # Inspect the crop data
>>> image.crops.data
{'rect': {'y': 0, 'width': 100, 'height': 50, 'filename': 'crops/test-rect.tiff', 'x': 0}}
>>> # Inspect the crop
>>> image.crops.rect.name
'crops/test-rect.tiff'
>>> image.crops.rect.path
u'/home/alen/projects/django-croppy/tests/test-media/crops/test-rect.tiff'
>>> image.crops.rect.url
'/test-media/crops/test-rect.tiff'
>>> # Save the data to database
>>> image.save()
>>> # Delete the crop
>>> image.crops.delete('rect')
>>> image.crops.data
{}
Metadata
Release files for django-croppy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-croppy-0.1.0.tar.gz | 6.4 kB | Without provenance | Details for django-croppy-0.1.0.tar.gz |
Release files / django-croppy-0.1.0.tar.gz
| Download URL | django-croppy-0.1.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
912d1b1b51a0de4c5e1563233ca5af2e967369dbf50b06f9b2d56bc147f4fd73
|
|
BLAKE2b-256 checksum How to use checksums |
f8e0d7d5b7d490bf786234bd032d64aa500ede1a37f0576c210775a642a4ed86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-croppy 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.