This question already has an answer here:
I'm trying to save the map canvas as an image in Python in QGIS. I've looked in a few places but haven't been able to get something to work. I need a function where I can specify the extent of the map and the image size. Very similar to the "snapshot" command line function that can be used with QGIS. But the problem with the snapshot function is that it has to start QGIS each time and then close it.