how can pass height and width to the imagekit templatetag?

153 Views Asked by At

views.py

class imagess(ImageSpec):
    processors = [SmartResize(100,100)]
    format = 'JPEG'
    options = {'quality': 100}

register.generator('main:imagess', imagess)

index.html

{% generateimage 'main:imagess' source=source_file %}

this generates a image of height 100 x 100

how can pass/define a custom height and width for the generated image from the HTML file....like

{% generateimage 'main:imagess' source=source_file height=1080 width=720 %}
1

There are 1 best solutions below

3
Siva Sankar On

Just add extra attributes and pass them in view function definition, you can use those parameters:

{% generateimage 'myapp:thumbnail' source=source_file height=1080 width=720 %}

Views.py

class imagess(ImageSpec, height, width):
    processors = [SmartResize(height, width)]
    format = 'JPEG'
    options = {'quality': 100}

register.generator('main:imagess', imagess)