It does not seem like Lua or Spring have build in functions to write images so you have to make something yourself.
The writing of files would work like writing text just instead of letters you write bytes. to do so, you have to open the file in binary mode.
The "w" in io.open() is the mode, for binary write probally "wb"
The .bmp format is probally less complex then the .jpg format because there is no compression.
Wiki has details on how a data is stored in a bitmap file:
http://en.wikipedia.org/wiki/BMP_file_format
Google also has many results on "bitmap loader tutorial", must stuff for other languages but the principle is the - oh wait, just found this:
http://springrts.com/wiki/Lua_OpenGL_Api#PixelReadback
gl.SaveImage
gl.ReadPixels