DantheMan
DantheMan

Reputation: 7417

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

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.

Upvotes: 5

Views: 6793

Answers (3)

DantheMan
DantheMan

Reputation: 7417

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

Upvotes: 7

mmcnickle
mmcnickle

Reputation: 1607

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.

Upvotes: 0

gurglet
gurglet

Reputation: 421

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

Upvotes: 3

Related Questions