michaelkuty / django_image_proxy

Simple Django Image Proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django Image Proxy

Small django toolkit for loading images from remote hosts. Supports custom sizes and simple caching for less API calls.

Supports

  • Django 1.7 +
  • Pillow 2.3.0

Installation

pip install django_image_proxy

Settings

Specify your remote host.

INSTALLED_APPS += ('image_proxy',)

IMAGE_PROXY_URL = 'http://localhost:9753/images'

Optionaly you can set some common properties.

THUMBNAILS_DIR = "thumbnails"

# disable caching
IMAGE_PROXY_CACHE = False

# change thumbnail format
THUMBNAILS_FORMAT = "PNG"

urls.py

urlpatterns = patterns('',
    ...
    url(r'^images/', include('image_proxy.urls')),
    ...
)

Usage

As url

<img src="{% url 'proxy_image' '/media/anotherdjangoapp.png' %}"/>
<img src="{% url 'proxy_image_preview' '/media/anotherdjangoapp.png' %}"/>
<img src="{% url 'proxy_image_size' 'my_image_name' '100x100' %}"/>
<img src="{% url 'proxy_image_full' 'my_image_id' '100x100' 'scale' %}"/>

As templatetag

{% load thumnail %}
{% thumbnail product.image %}
{% thumbnail product.image '400x400' %}
{% thumbnail product.image '400x400' 'crop' %}

If you have clash between your favourite thumbnail provider and proxy thumbanil tags use {% load thumbnail from proxy_thumbnail %}.

Custom size and method

http://<hostname>/<path_to_source_file>/<size>/<method>/
# simple using Django Rest Framework Serializer
# for image paths return something like this
images = ["/media/image.jpg", "/media/image01.jpg"]

for image in images:

    print reverse("proxy_image", args=[image])
    /images/image/media/image.jpg # this url download image from original url and returns it !

Usage with Openstack Horizon Dashboard

Requires installed horizon.

Image in modal dialog.

<a href="{% url 'proxy_image_preview' image %}" class="ajax-modal">
  <img src="{% thumbnail product.image '100x100' 'crop' %}" class="center-block" width="100px" />
</a>

Override

from image_proxy.views import ThumbnailView

class MyThumbnailView(ThumbnailView)

    def get(self, request, *args, **kwargs):

        response = http.HttpResponse(self.image, content_type=self.content_type)

        return response

Contribution

About

Simple Django Image Proxy


Languages

Language:Python 88.5%Language:HTML 11.5%