This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Resizing and cropping images via Nginx, as well as caching the result

pip install django-nginx-image

Features:

  • High-performance resize and crop via Nginx
  • Transparent caching an images
  • Template tag thumbnail for building correct URL for Nginx
  • The Django command for convert unsupported images formats (example, BMP) to JPG

For more details see:

Settings:

Add to settings.py:

INSTALLED_APPS = (
    'nginx_image',
)

Now, add two sections called server:

  1. The cache server www.example.org, which will connect to the second server and receive changed image and save the result to the cache.
  2. The image server image.example.org, which can to resize and to crop a images.

A sample of configuration file for your project:

http {

    proxy_cache_path <STORAGE_ROOT>/nginx/cache levels=1:2 keys_zone=<CACHE_NAME>:10m max_size=1G;

    server {
        listen 80;
        server_name www.example.org;

        location ~* ^/(resize|crop)/ {
            proxy_pass http://image.example.org$request_uri;
            proxy_cache <CACHE_NAME>;
            proxy_cache_key "$host$document_uri";
            proxy_cache_valid 200 1d;
            proxy_cache_valid any 1m;
            proxy_cache_use_stale error timeout invalid_header updating;
        }
    }

    server {
        listen 80;
        server_name image.example.org;

        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;
        }
    }
}

Where, STORAGE_ROOT is the path to directory with web-assests. For example I have in my settings.py:

STORAGE_ROOT = "/storage/kinsburg_tv"
MEDIA_ROOT = os.path.join(STORAGE_ROOT, "media")
STATIC_ROOT = os.path.join(STORAGE_ROOT, "static")

And “CACHE_NAME” is the arbitrarily name, example: “my_project_cache”.

Usage:

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 %}

Convert:

Unfortunaly, ngx_http_image_filter_module only supports JPEG, GIF and PNG, so you have to convert BMP to JPG:

./manage.py nginx_image_converter -i /storage/project/media -o /storage/project/newmedia

Available options:

-i SOURCE, --source=SOURCE
                    Source directory with pictures
-o DESTINATION, --destination=DESTINATION
                    Destination directory for save the pictures
-q QUALITY, --quality=QUALITY
                    Percentage of quality for images in JPG
-e, --change-extension
                    Change extension to "jpg"
Release History

Release History

0.3.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-nginx-image-0.3.2.tar.gz (4.5 kB) Copy SHA256 Checksum SHA256 Source Nov 19, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting