Capture a partial screenshot in the BGE I am looking for a way to capture just a portion of the screen in the game engine. I was using the built-in render.makeScreenshot(path), which only captures a full-screen PNG. 

I am exploring the following approach but have no idea how to save the list data into an image format. Any help would be appreciated.

from bgl import *
def captureCropped(posX, posY, sizeX, sizeY):
        buf = Buffer(GL_BYTE, [sizeX,sizeY,3])
        glReadPixels(posX,posY,sizeX,sizeY,GL_RGB,GL_BYTE,buf)
        ... #now what do I do with buf?
One solution is to uses plain Python to write out the PNG file.

Another solution is to extend render.makescreenshot(filename) to accept additional optional argument in the form of render.makescreenshot(filename, x, y, width, height)
The work-in-progress patch is here:
http://www.pasteall.org/47215/diff

Note: The patch currently does not work correctly in Blender, it only works in BlenderPlayer.