Skip to main content

Automatically add dimension attributes to all <img> tags in a response to improve rendering speed on the client.

Rationale

Specifying image dimensions in HTML improves both percieved and actual client-side rendering performance by preventing reflow. However, maintaining explicit dimensions in templates is tedious and impractical in some cases. This middleware solves that in a plug-and-play manner by automatically setting dimensions in all &img& tags in a response.

Requirements

  • django-celery to run image fetch and dimensions calculations in the background

  • PIL

  • A cache that is shared between web server and celery (e.g. memcached)

Installation

  1. Run pip install django-image-dimensions

  2. Add ‘imagedimensions’ app to INSTALLED_APPS

Usage

For a quick test-drive add ‘imagedimensions.middleware.ImageDimensionsMiddleware’ to MIDDLEWARE_CLASSES. However, this is not suitable for production use as it adds an overhead to every request. For production, replace {% load cache %} in your templates with {% load imgdimensions %}.

Metadata

Release files for django-image-dimensions 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-image-dimensions 0.0.4
File Size Uploaded Provenance Actions
django-image-dimensions-0.0.4.tar.gz 3.8 kB Without provenance Details for django-image-dimensions-0.0.4.tar.gz

Release files / django-image-dimensions-0.0.4.tar.gz

Download URL django-image-dimensions-0.0.4.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8ea669759d5b660c1cb79409caa4de4e22228ea9c64ddabdcedd6f5cf5af41c0
BLAKE2b-256 checksum
How to use checksums
1bc908a42ab8b2a3ecba0f90444ebcd0fb4872e73a4f4d2a5f56b9e0b31de6e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-image-dimensions 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page