Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Pillow with Django

Tags:

I installed Pillow and now want to use it on my Django site to allow uploading of images of through my admin page. See previous question.

What changes do I need to make in my settings file or elsewhere for Django to recognize Pillow and to allow the ImageField to upload the image properly?

like image 339
zpesk Avatar asked Feb 26 '13 02:02

zpesk


People also ask

What is the use of Pillow in Django?

The Pillow library contains all the basic image processing functionality. You can do image resizing, rotation and transformation. Pillow module allows you to pull some statistics data out of image using histogram method, which later can be used for statistical analysis and automatic contrast enhancement.

Does Django need Pillow?

Using PIL/Pillow is only required if you want to do image processing.

How do I use the pillow library in Python?

Here we will discuss the Pillow module of Python. Python Pillow is built on the top of PIL (Python Image Library) and is considered as the fork for the same as PIL has been discontinued from 2011. Pillow supports many image file formats including BMP, PNG, JPEG, and TIFF.

Is Pillow the same as PIL?

What is PIL/Pillow? PIL (Python Imaging Library) adds many image processing features to Python. Pillow is a fork of PIL that adds some user-friendly features.


2 Answers

The problem is that imports now work slightly differently with Pillow vs PIL. The differences are described here: http://pillow.readthedocs.org/en/latest/porting-pil-to-pillow.html

Django has also now been changed to prefer Pillow over PIL, via this ticket (https://code.djangoproject.com/ticket/19934)

This commit is present in the new Django 1.6a1 release, so the new behaviour will be present in the Django 1.6 release. For now, however, it appears that you can use a new library (initially released May 20, 2013) called Pillow-PIL which will provide a compatibility layer. This can be easily installed with pip via: pip install --pre Pillow-PIL

like image 169
Joey Wilhelm Avatar answered Oct 30 '22 08:10

Joey Wilhelm


First, install pillow (having virtualenv activated preferably) with:

pip install pillow

You should import it in Django project:

from PIL import Image

After that you don't need to change settings or anything else. All the modules should work.

like image 45
Ria Avatar answered Oct 30 '22 06:10

Ria