Django Imagekit is processing the original image
With version 1.1 I don't understand how I can preprocess the original image (just using imagekit)
https://github.com/jdriscoll/django-imagekit/blob/develop/README.rst
The presence of such a model:
class Photo(models.Model):
original = models.ImageField(etcetera)
thumbnail = ImageSpec(etcetera)
How can I resize the original image? This was possible in the previous samples, however the documentation outlines that I need another modelfield?
a source to share
You can use ProcessedImageField
:
from imagekit.models import ProcessedImageField
class Photo(models.Model):
original = ProcessedImageField(etcetera)
There is code documentation in this class , but it looks like it's not picked up by the readthedocs ' autodoc module right now.
I reopened the bug to fix the documentation.
a source to share
Looking here: https://github.com/jdriscoll/django-imagekit/blob/master/imagekit/processors/resize.py it looks like the class Fit
is what you need.
Unconfirmed, but I suspect it is something like:
from django.db import models
from imagekit.models import ImageSpec
from imagekit.processors import resize
class Photo(models.Model):
original_image = models.ImageField(upload_to='photos')
thumbnail = ImageSpec([resize.Fit(50, 50)], image_field='original_image',
format='JPEG', options={'quality': 90})
a source to share
Below you will do what you are looking for. You can also add other processors to the processor list. The processors are started before the image is saved.
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFit
class Photo(models.Model):
original = ProcessedImageField(
upload_to='images/%Y%m',
format=JPEG,
processors=[ResizeToFit(200, 100)],
options={'quality': 90}
)
a source to share