I have a serious problem with PIL (Python Image Library) in Django and have jumped through a lot of hoops and still have not been able to figure out what is the root of the problem.
The problem essentially boils down to the inability to upload JPEG images through ImageField in the Django admin. But the problem is not as simple as installing libjpeg.
At first I installed PIL (via Buildout) and realized, as soon as it was installed, that I did not install libjpeg because JPEG support was not available.
Without setting up the server itself, I just assumed that it was not installed, and I compiled libjpeg 8 from the source. This ended in my directory / usr / local / lib / . I cleaned up my Buildout files and rebuilt everything. This time, when PIL was compiled, I had JPEG support. But I went to the Django admin and tried to upload a JPEG, although ImageField was out of luck. I got "Upload the correct image. The uploaded file was either not an image error or a corrupted image." Just like a test, I opened the Djano shell and performed the following:
> import Image
> i = Image.open( "/absolute_path/file.jpg" )
> print i
<JpegImagePlugin.JpegImageFile image mode=RGB size=940x375 at 0x7F908C529BD8>
This runs without errors and shows that PIL can open JPEG files.
After some reading, I come across this question:
Is it possible to control which libraries use apache?
, PHP libjpeg Django, libjpeg 6.2 . lsof:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 2561 www-data mem REG 202,1 146032 639276 /usr/lib/libjpeg.so.62.0.0
, , libjpeg 6.2. libjpeg, /usr/local/lib. PIL, , dev/header libjpeg, PIL. libjpeg aptitude uninstaller (sudo aptitude remove libjpeg62). , , , PIL, libjpeg, aptitude: ( sudo aptget install libjpeg62-dev).
Buildout Buildout, , , PIL. , JPEG, libjpeg62.
, Django Admin. JPEG. JPEG , , . , JPEG:
import Image
i = Image.open( "/absolute_path/file.jpg" )
v = i.verify()
HTML, . . , :
{{ i }} - <JpegImagePlugin.JpegImageFile image mode=RGB size=940x375 at 0x7F908C529BD8>
{{ v }} - None
, :
- JPEG, ?
- - , libjpeg?
- libjpeg, PNG ?
, 2 .
:
1. Rackspace
2. Ubuntu 10.04
3. Django 1.2.3 ( Buildout)
4. PIL 1.1.7 ( Buildout)
5. libjpeg 6.2 ( aptitude (sudo aptget install libjpeg62-dev)