ImageMagick has a command line tool called composite that will do what you want. Distributions are available for Windows, Mac, Linux, etc. I just checked it with two transparent PNGs and it works as expected.
composite foreground.png background.png newimage.png
Adam source
share