Posts tagged ‘pygame’

Image Manipulation in Python 3

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.