Laying out some imges

I have an array of images I want to set them out in a grid with some padding. If the total image width + the padding is greater then the stagewidth I want to create a new row.

Has anyone written a class or function to tackle this problem?

thanks,

RK