0

I am trying to use image-kit with admin image uploads. In my edit form there are fields for width and height. I need a way to pass these values to image-kit's processors.

But i can not find a way... ?

ratata
  • 1,129
  • 14
  • 42

1 Answers1

0

The answer is :
Imagekit version is development version (2, 0, 0, 'alpha', 1) Suppose we are in image model admin.py


this function will be used as callable, instance is the image object

def getThumb(file, instance): return [resize.ResizeToFill(width=instance.width, height=instance.height)]

class Image(Media):
width = models.IntegerField(blank=True, null=True) height = models.IntegerField(blank=True, null=True)

file = models.ImageField(upload_to='static/uploads/images/bigs')  
### IMAGE-KIT we are passing a callable function as processors to ImageSpecField 
thumbnail = ImageSpecField( processors = getThumb, image_field='file', format='JPEG', options={'quality': 90}) 

### override admin save function
def save(self, *args, **kwargs):       
    # Call the "real" save() method in the base class 'models.Model'        
    super(Image, self).save(*args, **kwargs) 
    test = Image.objects.all()[0]  
    test.thumbnail.width ### getting a property means completing upload of imagekit file
ratata
  • 1,129
  • 14
  • 42