Sonata media gallery
Usually Gallery or Media entity are related to other entities and we retrieve them from their relation. e.g. from owner of a gallery or related medias to a product. after fetching pass media object(image in this case) to template(twig or php) and use sonata media helpers to display them.