PIL

Pythonから画像を扱うためにPILをインストール。PILはPython Imaging Libraryの略で、最新のものはここからダウンロードできます。
いつもどおり、setup.py。
あらよっと使ってみるとこんなエラーが。

Traceback (most recent call last):
  File "/usr/local/zope/cms/Products/Archetypes/Field.py", line 2228, in createScales
    imgdata, format = self.scale(data, w, h)
  File "/usr/local/zope/cms/Products/Archetypes/Field.py", line 2272, in scale
    image.thumbnail(size, self.pil_resize_algo)
  File "/usr/local/lib/python2.4/site-packages/PIL/Image.py", line 1522, in thumbnail
    self.load()
  File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line 180, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "/usr/local/lib/python2.4/site-packages/PIL/Image.py", line 375, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available

PILのREADMEを読むと、Prerequisitesのところにこんな記述がありました。

1. Prerequisites.

   If you need any of the features described below, make sure you
   have the necessary libraries before building PIL.

   feature              library
   -----------------------------------------------------------------
   JPEG support         libjpeg (6a or 6b)

                        http://www.ijg.org
                        http://www.ijg.org/files/jpegsrc.v6b.tar.gz
                        ftp://ftp.uu.net/graphics/jpeg/
(以下略)

libjpegをインストールしないといけないんですね。libjpegのインストール記録は2007年2月8日のエントリにあります。この通りにインストール。ついでにFreeTypeもインストール。そして再度PILをインストールします。

$ cd Imaging-1.1.6
$ python setup.py build_ext -i
(中略)
----------------------------------------------------------------
PIL 1.1.6 BUILD SUMMARY
----------------------------------------------------------------
*** TKINTER support not available (Tcl/Tk 8.3 libraries needed)
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE support ok
----------------------------------------------------------------
$ python setup.py build
# python setup.py install

と。使えるようになりました。