Image Manipulation in Python 3

By | April 14, 2010

Enough libraries have been ported to Python 3 to finally make it seriously possible to write real world code in this modern Python interpreter. Sure, we don’t have django or really any decent web framework yet (CherryPy runs, but it’s not a full web stack), and database support is limited (SQLAlchemy supports postgres and sqlite3), but for the most part, if you need to do something Python 3, you can.

The major exception I’ve discovered is Image manipulation. The Python Imaging Library has not been ported to Python 3, and there is no indication when it will be. The latest version of PIL, 1.1.7 was released in late 2009, with an indication that it would be “made available for Python 3,” but no estimate as to timeline. There are no mailing list posts answering an increasingly popular question “when will PIL be available for python 3?” I found no source repositories that indicate that it has been started. There is a patch floating around that can supposedly be applied to PIL 1.1.6 to make it Python 3 compatible, but it didn’t work for me.

I tried doing a port of PIL 1.1.7 myself, but was unable to find documentation for the modifications to the C extension API in Python 3. My C is pretty rusty, and my schedule is way too full for the next two months, so I gave up on the task. Because of the lack of support from the official PIL developers (I hold nothing against them; we’re all busy in the open source world, and can only contribute what we have time and interest to contribute), I’m hoping this post will motivate someone to attempt a port of PIL, making Python 3 that much more attractive.

If you came to this post looking for some kind of Python 3 image manipulation library and were disappointed, don’t be! The Pygame image module allows us to load a few image formats, and we can manipulate the resulting surfaces in a variety of ways. It’s lower level and not as comprehensive as the Python Imaging Library, but it is one useful alternative if you need to do image manipulation in Python 3.

3 thoughts on “Image Manipulation in Python 3

  1. Allan

    Hopefully with the python-2.7 being scheduled to be the last in the 2.x series and the lack of changes between 2.6 and 2.7 due to the moratorium on core language changes, projects will no longer need to spend lots of time porting up to the latest 2.x release and can start the focus on porting to python-3.x. At least some on the major libraries are on their way to being done (pyqt = done, pygtk2 = some patches available, numpy = done in trunk)

    I found pygame 1.9.0 support for python3 quite incomplete for general game usage (which is known), although I can not specifically remember any issues with basic image manipulation. pgreloaded (aka pygame2) looks like it shaping up quite well for an alpha release.

  2. Jeroen

    PIL seems to be dying a little bit, the mailinglist is inactive since 24 november 2009.


Leave a Reply

Your email address will not be published. Required fields are marked *