I have a multi-layered PSD, with one specific layer being non-rasterized text. I'm trying to figure out a way I can, from a bash/perl/python/whatever-else program:

1. load the PSD
2. edit the text in said layer
3. flatten all layers in the image
4. save as a web-friendly format like PNG or JPG

I immediately thought of [ImageMagick](http://www.imagemagick.org/), but I don't think I can edit the text layer through IM. If I can accomplish the first two steps some other programmatic way, I can always use ImageMagick to perform the last two steps.

After a couple of hours of googling and searching CPAN and PyPI, I still have found nothing promising. Does anyone have advice or ideas on the subject?