I typically use PMView for my (simple) image processing needs, but have played with XnView a little. (It's got a nice web page generator.) It works with a lot of image formats. [link|http://perso.wanadoo.fr/pierre.g/xnview/enhome.html|XnView].
He also has a tool called [link|http://perso.wanadoo.fr/pierre.g/xnview/en_ncfeatures.html|NConvert] that may be perfect for your needs. I don't know if they handle the details of what you're trying to do though.
They're both freeware and run on just about anything.
HTH a bit.
Cheers,
Scott.