I'm writing a program that generates reports from a database. The reports consist of a grid of images with textual information about each image centered above the image. For various reasons, I'm using SVGs as templates for the reports which I'm then modifying using HTML::Template.
My problem is that I need to be able to center the text above each image. I know exactly where each image will be placed, but since I don't know how wide the text will be, I don't know where to place it relative to the image. In some cases the text might only be a single word; in other cases it could be five times that long. Is there a way to calculate SVG text widths? Any other ideas about how I can center the text?