[Haskell-cafe] Haskell image libraries

Andrew Coppin andrewcoppin at btinternet.com
Sun Nov 8 09:58:00 EST 2009

Max Rabkin wrote:
> Haskellers,
> To add image support to fdo-notify, I need an image type. Looking
> through Hackage, I didn't find any image library with the following
> features:
> * Load from a variety of formats (at least PNG and JPG, I'd say)
> * Efficient per-pixel access, or a way to dump the image into a
> ByteString as a bitmap (I need to serialise them into the protocol's
> bitmap format)
> Preferably, it should be possible to construct images programmatically too.
> Is there really no such library? It would be nice to have something
> like a Haskell equivalent of the Python Imaging Library, which is the
> de facto standard image library in Python and supports just about
> every type of operation on images you could ask for.
> Regards,
> Max

Try AC-EasyRaster-GTK. It's a thin layer over Gtk2hs that I wrote 
precisely because it's so fiddly to do bitmapped graphics with Gtk2hs. 
(Vector graphics is delightfully easy with Cairo, but bitmap graphics 
requires manual bit-twiddling, and lots of simple but non-obvious API 

In particular, Easy Raster will trivially load and save PNG and JPEG 
images, and provide pixel-level read/write functions (either with or 
without bounds checks).

What I haven't implemented is access to the underlying pixel array. 
There's a function ib_pixmap which will get you the GTK Pixmap object, 
from which you can obtain the pixel array. But it's not an IOArray or 
STArray or anything like that; it's some other datatype that implements 
the MArray class, so it doesn't buy you much. You might as well just use 
the pixel read/write functions from Easy Raster and manually iterate all 

(Another annoying quirk is that Gtk2hs doesn't provide a way to read or 
write an image from a handle, only from a real file, so naturally Easy 
Raster shares the same limitation.)

More information about the Haskell-Cafe mailing list