I found Exporting composition as image using PyQGIS to export the current view as an image.
The following code works and was accepted as an answer.
c = iface.activeComposers()[0].composition() image = c.printPageAsRaster(0) image.save('output.png', 'png')
Sadly, the images produced by this code are not georeferenced, even if I use different image formats.
How is it possible to programmatically export current view as georeferenced image with QGIS?