Пример работы (делаем масштабирование картинки по ширине и высоте, но не превосходящее width_max, height_max):
from django.db import models from django.forms.fields import CharField from imagekit.models import ImageSpec from imagekit.processors import resize, Adjust from django.forms import ModelForm, forms class FormatImage(object): def process(self, image): # масштабируем до width_max, height_max width_max=605 height_max=475 c=resize.Fit(width_max,height_max,True) image=c.process(image) return image class Photo(models.Model): original_image = models.ImageField(upload_to='photos') formatted_image = ImageSpec([FormatImage()],image_field='original_image', format='JPEG', options={'quality': 90},cache_to='photos/formatted/') thumbnail = ImageSpec([Adjust(contrast=1.2, sharpness=1.1), resize.Crop(50, 50)], image_field='original_image', format='JPEG', options={'quality': 90},cache_to='photos/thumbnail/') info=models.TextField()
Свежие комментарии