How to resize an Image with fixed height and variable width

415 views
Skip to first unread message

Bala Subramanyam Vemu

unread,
Dec 11, 2014, 9:20:09 AM12/11/14
to django-...@googlegroups.com
Hi

How can I create a spec file with fixed height and specify the width as a variable

Thanks
Bala

matthewwithanm

unread,
Dec 11, 2014, 10:23:26 AM12/11/14
to django-...@googlegroups.com
You mean like this?


from imagekit import ImageSpec
from imagekit.processors import SmartResize

class MySpec(ImageSpec):
    def __init__(self, width):
        self.width = width

    @property
    def processors(self):
        return [SmartResize(self.width, 100)]

matthewwithanm

unread,
Dec 11, 2014, 10:29:29 AM12/11/14
to django-...@googlegroups.com
Sorry, forgot the source kwarg in __init__ (and the super call!), but same idea.

If you're talking about basing it on a model property, that's covered in the "Specs That Change" section of the advanced usage docs.

Bala Subramanyam Vemu

unread,
Dec 12, 2014, 1:40:29 PM12/12/14
to django-...@googlegroups.com
Hi Matthew

Thanks for Your reply

I figured out that the following preprocessor will generate cache images based on fixed height and variable width

self.processors = [ResizeToFit(height=1800)]

Thanks again for the great code
Bala

Bala Subramanyam Vemu

unread,
Dec 12, 2014, 1:55:36 PM12/12/14
to django-...@googlegroups.com
By the way I am using pilkit for processing the images

Thanks
Bala

--
You received this message because you are subscribed to a topic in the Google Groups "Django ImageKit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-imagekit/s-xkLTn1bLA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-imagek...@googlegroups.com.
To post to this group, send email to django-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-imagekit/405ccb13-60fe-48bd-aaab-fa17b267c06b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

matthewwithanm

unread,
Dec 12, 2014, 2:17:52 PM12/12/14
to django-...@googlegroups.com
Ah, I see now. Glad you figured it out, and thank you for the nice words!
Reply all
Reply to author
Forward
0 new messages