codingjoe / django-pictures

Responsive cross-browser image library using modern codes like AVIF & WebP
BSD 2-Clause "Simplified" License
248 stars 20 forks source link

Override img[width] and img[height] attributes #176

Closed codingjoe closed 3 months ago

codingjoe commented 3 months ago

Hi @codingjoe,

The library offers extensive functionality and simplifies the transition from legacy <img> tags to the modern <picture> tags. While I appreciate the push towards using <picture>, there are numerous scenarios where explicitly setting image sizes is beneficial.

Currently, the <picture> tag inherits the original image size from the <img> tag, affecting the resulting container as well. So every image insertion will have the original image's size on website in some cases. Although reverting to the legacy implementation is an option, it undermines the benefits of upgrading from django-stdimage to django-pictures.

What do you think about adding an ability to set explicit image size from template tag?

Originally posted by @atnartur in https://github.com/codingjoe/django-pictures/discussions/147#discussioncomment-9872150

codingjoe commented 3 months ago

The attributes are rended in this line: https://github.com/codingjoe/django-pictures/blob/96af07eeb7b68968d4b2b3a6d10dbba275834873/pictures/templates/pictures/picture.html#L5

When we move, the height and width attributed to the img_attrs dictionary as defaults, they can be overwritten via {% picture foo.bar img_height=600 img_height=800 %}

Go ahead @atnartur with your patch, thanks!

Best Joe