How to combine dynamic image spec with static one?

27 views
Skip to first unread message

Igor

unread,
Dec 29, 2015, 1:23:07 AM12/29/15
to Django ImageKit
I'm trying to figure out how to Crop() based on model saved dimensions while using accessor name for resizing.
Example:

class AvatarThumbnail(ImageSpec):
    format
= 'JPEG'
    options
= {'quality': 60}

   
@property
   
def processors(self):
        model
, field_name = get_field_info(self.source)
       
return [
           
Crop(width=model.thumbnail_width, height=thumbnail.avatar_height),
           
ResizeToFill(?????????????),
       
]
register.generator('myapp:profile:avatar_thumbnail', AvatarThumbnail)


class Profile(models.Model):
    avatar
= models.ImageField(upload_to='avatars')
    small_thumbnail
= ImageSpecField(source='avatar',
                                      id
='myapp:profile:avatar_thumbnail')
    large_thumbnail
= ImageSpecField(source='avatar',
                                      id
='myapp:profile:avatar_thumbnail')
   
    thumbnail_width
= models.PositiveIntegerField()
    thumbnail_height
= models.PositiveIntegerField()


In this example how would ResizeToFill change dimensions based on `small_thumbnail` vs `large_thumbnail`?

Thanks!

Igor

unread,
Dec 30, 2015, 12:23:29 PM12/30/15
to Django ImageKit
solved this with
class Profile(models.Model):

 
@property
 
def small_thumbnail(self):
   
self.sizes = (50,50)
   
return self._spec

 
_spec =ImageSpecField(source='avatar',
   id='myapp:profile:avatar_thumbnail')

then inside spec I pick it up from model.sizes
Reply all
Reply to author
Forward
0 new messages