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 hashes)

Uploaded Source

Supported by

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