Saturday, December 17, 2011

JPEG Support for Python 2.7's PIL Module on OS X Lion

My PIL module refuse to process jpeg image. It says that there is no decoder jpeg on my system. It's no good  since I want to process that kind of file using PIL in future, and my older iPhoto picture on my 13 inch MacBook Pro is generally in jpeg format too.

Here the snapshot

Nugrohos-MacBook-Pro:olah gambar nugroho$ python 
Program Image Enchancement
Oleh Nugroho Adi Pramono
format awal:  JPEG 2448x3264 RGB
konversi ke grayscale
Traceback (most recent call last):
  File "", line 14, in 
    gbw = gb.convert("L")
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/", line 679, in convert
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/", line 189, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/", line 385, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
Nugrohos-MacBook-Pro:olah gambar nugroho$ 

So I googling for it and found libjpeg at, download, exctract and install it using magic UNIX words ./configure, make, make install

Nugrohos-MacBook-Pro:~ nugroho$ cd Downloads/jpeg-8c/
Nugrohos-MacBook-Pro:jpeg-8c nugroho$ ./configure 
Nugrohos-MacBook-Pro:jpeg-8c nugroho$ make
Nugrohos-MacBook-Pro:jpeg-8c nugroho$ make test
rm -f testout*
./djpeg -dct int -ppm -outfile testout.ppm  ./testorig.jpg
./djpeg -dct int -bmp -colors 256 -outfile testout.bmp  ./testorig.jpg
./cjpeg -dct int -outfile testout.jpg  ./testimg.ppm
./djpeg -dct int -ppm -outfile testoutp.ppm ./testprog.jpg
./cjpeg -dct int -progressive -opt -outfile testoutp.jpg ./testimg.ppm
./jpegtran -outfile testoutt.jpg ./testprog.jpg
cmp ./testimg.ppm testout.ppm
cmp ./testimg.bmp testout.bmp
cmp ./testimg.jpg testout.jpg
cmp ./testimg.ppm testoutp.ppm
cmp ./testimgp.jpg testoutp.jpg
cmp ./testorig.jpg testoutt.jpg
Nugrohos-MacBook-Pro:jpeg-8c nugroho$ sudo make install

reinstall PIL

version       1.1.7
platform      darwin 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
              [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the script.