5

I have PIL installed, however whenever I try to upload a .png file to an image field through the Django Admin for my model, I get this error:

"Upload a valid image. The file you uploaded was either not an image or a corrupted image."

Other image types work fine. I have tried several different PNG files.

I have tried rebuilding PIL after installing pypng, libpng-dev, etc.. and am on ubuntu server.

Pierre de LESPINAY
  • 42,450
  • 54
  • 205
  • 294
DantheMan
  • 6,967
  • 7
  • 31
  • 35

3 Answers3

7

This issue was solved by using pip to install "pillow" instead of "pil" which allows easy deployment to virtualenv.

DantheMan
  • 6,967
  • 7
  • 31
  • 35
3

When you compile PIL it should say if it has been compiled with PNG support or not, but if you have problems installing it yourself, I would recommend that you use the version that comes with ubuntu. It's strangely named but easily installed with:

apt-get install python-imaging
gurglet
  • 320
  • 1
  • 2
  • 11
0

I have found that building PIL on Ubuntu can cause problems because libpng is in a non standard location, and PIL can't find it.

In the folder that PIL has been downloaded to, edit setup.py. Find the following line:

JPEG_ROOT = None

and change it to

JPEG_ROOT = '/usr/lib/i386-linux-gnu/'

then rebuild PIL and check for the messages near the end that PNG support is included.

I know it's odd to modify JPEG_ROOT when you want to add PNG support, but setup.py will look in JPEG_ROOT for libpng too.

mmcnickle
  • 1,599
  • 10
  • 13