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

I have PIL installed, however whenever I try to load a PNG file into the image field via Django Admin for my model, I get this error:

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

Other types of images work fine. I tried several different PNG files.

I tried to restore the PIL after installing pypng, libpng-dev, etc. and on the ubuntu server.

+4
source share
3 answers

When you compile PIL, it should say whether it was 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 is strangely named, but easily installed with:

apt-get install python-imaging 
+2
source

This problem was solved with pip to install a cushion instead of a pil, which makes it easy to deploy a virtual machine.

+6
source

I found that creating PIL on Ubuntu can cause problems because libpng is in a non-standard location and PIL cannot find it.

In the folder into which the PIL was downloaded, edit setup.py . Find the following line:

 JPEG_ROOT = None 

and change it to

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

then reconfigure PIL and check for PNG support messages at the end of the message.

It's hard for me to change JPEG_ROOT if you want to add PNG support, but setup.py will also look in JPEG_ROOT for libpng .

0
source

Source: https://habr.com/ru/post/921507/


All Articles