Search code examples
djangoimagedimensions

Accessing image dimensions on an ImageField in a Django template?


I have ImageField in my model and I'm able to display the image in a template. However, how do I retrieve the image's height and width?


Solution

  • See the documentation for ImageField.

    In addition to the special attributes that are available for FileField, an ImageField also has height and width attributes.

    So just do the following:

    <img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}"/>