Django image renderer

Build Status Coverage PyPI Version

Django image renderer is an app that will help you render images in many sizes (renditions). This can be really helpful for generating images size for different screens resolution (especially when targeting mobile).


Quick start

Install the app.

pip install django-image-renderer

Add "renderer" to your INSTALLED_APPS setting like this:

    # your apps

Include the renderer URL configuration in your project like this:

url(r'^renderer/', include('renderer.urls', namespace='renderer'))),

Run python migrate to create the renderer models.

Start the development server and visit http://localhost:8000/admin/ to create a MasterImage (you'll need the Admin app enabled).



There is only one model in the app: MasterImage. With a MasterImage you can ask for renditions.

m = MasterImage.objects.first()

# get the master file's URL
# or
m.get_rendition_url(0, 0)

# cache and return URL of a renditions that as 200 pixels width
# and height computed according to master's aspect ratio
url = m.get_rendition_url(200, 0)

# cache and return URL of a renditions that as 50 pixels height
# and width computed according to master's aspect ratio
url = m.get_rendition_url(0, 50)

If you ask for a size that do not fit master's aspect ration you'll receive a center cropped image.

You can also ask for a rendition in templates.

def index(request):
    m = MasterImage.objects.first()
    return render(request, 'demo/index.html', {
        'master': m,


{% load renderer %}
{% rendition master 42 42 %}

This will render as:

<img src="/media/img/0fb34de8-9d83-456a-828b-72ab21f8ebab_42x42.png" width="42" height="42" alt="">

When using MasterImage in your model you may need a widget who provides a preview for you image. For convenience a mixin is provided.

from django.db import models

class DemoModel(models.Model):
    master = models.ForeignKey('renderer.MasterImage')

from demo.models import DemoModel
from django.contrib import admin
from renderer.widgets import MasterImageAdminMixin

class DemoModelAdmin(MasterImageAdminMixin, admin.ModelAdmin):
    fields = ('master', )