Function to display a grid of images