[Tutor] [Tkinter-discuss] displaying an image

eryksun eryksun at gmail.com
Fri Oct 5 06:39:54 CEST 2012


On Thu, Oct 4, 2012 at 3:31 PM, Matthew Ngaha <chigga101 at gmail.com> wrote:
>> You need to install PIL to use the tutorial you are doing.
>>
>> http://www.pythonware.com/products/pil/
>
> the site says
> "
> The current free version is PIL 1.1.7. This release supports Python
> 1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be
> released later.
> "
>
> i have python 3. all the downloads below it only show python 2
> versions. am i stuck?:(

If you're using Windows, Christoph Gholke has an installer for an
unofficial port to 3.2/3.3 for 32-bit and 64-bit platforms:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil

He also has the ported source code available to build PIL on a
non-Windows platform. But be forewarned this is rarely a simple
process. Below I've stepped through compiling the ported code on my
Debian system. But your mileage will *probably* vary...

Extract the source and change to the directory. Switch to your root
account and update/install the development packages. I'm skipping TIFF
support since Debian's libtiff4-dev package doesn't have the private
header (tiffiop.h) needed for PIL's experimental TIFF support.

Steps:

    $ sudo su
    # apt-get update
    # apt-get install build-essential python3-dev tk8.5-dev \
        libjpeg8-dev liblcms1-dev libfreetype6-dev


Two files need to be edited before building the extension modules.

(1) As is, the library files for the optional features won't be found.
You could symlink the required library files to /usr/lib, but I'd
rather modify setup.py. After line 229 in setup.py, add the lib
directory that Debian uses:

    For a 32-bit platform, add the following:

        add_directory(library_dirs, "/usr/lib/i386-linux-gnu")

    For a 64-bit platform, add the following:

        add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")


(2) In _imagingft.c: font_getsize, someone modified the source to use "max".

    Original:

    PIXEL(self->face->size->metrics.height)

    Modified:

    PIXEL(max(
        self->face->size->metrics.height,
        self->face->bbox.yMax - self->face->bbox.yMin))

"max" isn't defined, however, so you have to add a macro. I defined it
on line 21:

    #define max(a,b) ((a) > (b) ? a : b)


With those two edits, you should be able to build the extension
modules in place:

    # python3 setup.py build_ext -i

Run the tests:

    # python3 selftest.py

I get the following output:

    --- PIL CORE support ok
    --- TKINTER support ok
    --- JPEG support ok
    --- ZLIB (PNG/ZIP) support ok
    --- FREETYPE2 support ok
    --- LITTLECMS support ok
    ------------------------------
    Running selftest:
    --- 57 tests passed.


Now do the full the installation:

    # python3 setup.py install

Then from the same directory start python3 and test showing an image:

    >>> from PIL import Image
    >>> img = Image.open('Images/lena.png')
    >>> img.show()


More information about the Tutor mailing list