Time and again I’ve seen that programming on stuff for fun ends up teaching me intresting new things.
Up until now, I had been always hacking around with lisp only in the context of the emacs editor (since emacs has lisp interpreter that allows us to customize emacs).
Today, I figured I might as well put together some scheme code see how it feels. Since the Gimp is pretty much the “scheme supporting tool” that I have used most, I started looking for an API. Not suprisingly the API was not to difficult to find. It was right there in the Gimp.(File → Xtns → Procedure Browser). In fact, the gimp also provide a simple rep(read/execute/print) console where one can type in scheme lines of code and execute them (very similar to ruby’s irb)
In the process of getting to know the gimp’s I saw that it was pretty easy to extract out layers from an image. This function is understandably named: gimp-image-get-layers and takes an image object as its argument.
The coolest part is that function can be used to extract out the layers of a PSD. Hence, if I had a psd and wanted to pull out all the images in it while converting it into an CSS/XHTML file, I can use the gimp to do.
After some hacking around and going through the existing scripts in the gimp registry I discovered this script for exactly the same task.
$ cd ~/.gimp-x.y/scripts $ wget http://blog.quineloop.com/code/sg-save-all-layers.scm . $ gimp &
You will see the “File→Save all layers” menu item after you open a layered image!