2👍
✅
You can use ProcessedImageField
:
from imagekit.models import ProcessedImageField
class Photo(models.Model):
original = ProcessedImageField(etcetera)
There is in-code documentation on this class, but it looks like it’s not being picked up by readthedocs‘ autodoc module right now.
I reopened a bug to fix the documentation.
0👍
Looking here: https://github.com/jdriscoll/django-imagekit/blob/master/imagekit/processors/resize.py it looks like the Fit
class is what you’re after.
Untested but I suspect it’s 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})
- [Answered ]-Render list on template
- [Answered ]-Django sites framework custom settings for each site
- [Answered ]-Error when Overriding Django ModelForm field
- [Answered ]-Updating related/nested resource (user/userprofile) – Seeing a duplicate key error on PATCH
- [Answered ]-Django Multiple db with read only
0👍
Below will do what you are looking for. You can add other processors to the list of processors as well. The processors are run prior to saving the image.
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}
)
- [Answered ]-Where to initialize MongoDB connection in Django projects?
- [Answered ]-Why doesn't Apache display 404 errors with Django and mod_wsgi?
- [Answered ]-Software as a service in Django – many companies should be able to have the same users
- [Answered ]-How to setup email verification/confirmation in Django/Pinax?
- [Answered ]-Delete record in Django db with ajax
Source:stackexchange.com