Skip to main content

Resizing and cropping images via Nginx, and cache the result

Project description

http://adw0rd.com/media/uploads/django_nginx_image.jpg

Resizing and cropping images via Nginx, and cache the result

pip install django-nginx-image

For more details see:

Settings:

Add to settings.py:

INSTALLED_APPS = (
    'nginx_image',
)

Add to the configuration file of Nginx:

location ~* ^/resize/([\d\-]+)/([\d\-]+)/(.+)$ {
    alias <STORAGE_ROOT>/$3;
    image_filter resize $1 $2;
    image_filter_buffer 2M;
    error_page 415 = /empty;
}

location ~* ^/crop/([\d\-]+)/([\d\-]+)/(.+)$ {
    alias <STORAGE_ROOT>/$3;
    image_filter crop $1 $2;
    image_filter_buffer 2M;
    error_page 415 = /empty;
}

location = /empty {
    empty_gif;
}

Using:

In the templates can be used as follows:

{% load nginx_image %}

Proportionally resize a image, based on the width and the height:
    {% thumbnail user.profile.avatar 130 130 %}

Proportionally resize a image, based on the width:
    {% thumbnail user.profile.avatar 130 '-' %}
    {% thumbnail user.profile.avatar 130 0 %}
    {% thumbnail user.profile.avatar 130 %}

Proportionally resize a image, based on the height:
    {% thumbnail user.profile.avatar '-' 130 %}
    {% thumbnail user.profile.avatar 0 130 %}

Crop a image:
    {% thumbnail user.profile.avatar 130 130 crop=1 %}
    {% thumbnail user.profile.avatar 130 0 crop=1 %}
    {% thumbnail user.profile.avatar 0 130 crop=1 %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-nginx-image-0.1.tar.gz (2.2 kB view details)

Uploaded Source

File details

Details for the file django-nginx-image-0.1.tar.gz.

File metadata

File hashes

Hashes for django-nginx-image-0.1.tar.gz
Algorithm Hash digest
SHA256 18e7deaf53955d901a4356d99f255a4c3c4f2f09c0e6c3c05dc3a4be42a0cd89
MD5 0f11757bd574dc57e4a867c44d48adbe
BLAKE2b-256 b9962b1d83625d75fd31c871f796ae2d705cbc42a31762f5b17351f476a421de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page