So I've searched through the SO for half an hour and couldn't find answer.
I have to render picture where user can dinamically enter the font size, picture dimension and message. That message has to be vertically and horizontally centrally aligned over the picutre. I just can't get it right, it would be ok if the text is short, but user can enter anything in URL (example):
http://localhost:8080/app/slika?size=16&dim=100x200&msg=Java%20rulesfaekofakoefaeofae
Back-end is done by JSP and Java, here is the code of jsp file:
<body>
<div>
<img src="fruits.png" width="${ width }" height="${ height }" style="vertical-align: middle">
<%
int centerWidth = (Integer) request.getAttribute("width") / 2;
int centerHeight = (Integer) request.getAttribute("height") / 2;
%>
<span
STYLE="position:absolute; left:<%= centerWidth/2 %>; top:<%=centerHeight %>;
text-align:center; font-size:${ fontSize }px; width=100%">${ message }
</span>
</div>
You can see that I "kinda" hardcoded it, so for short messages the display will be fine, but for long it won't (as the text will go over the image, and it should break into next line).
That last sentence is what is bothering me, how to break text into the next line? I managed to align it, but can't break it.