Best way to get the resulting pixels of a layer group?

In my Lua script I want to get a merged image of the layer group, the same as what is displayed in the editor.