I am writing an ios application that can create a word cloud or text mosaic with a template selected by the user. My question is, how can I calculate the coordinates of each word, given that the sizes of each word are randomly calculated? Or any other approach?

Note that the template I want to work on is as follows:

but, most likely, my application will fill the white areas with an elephant mosaic, saving the user's photo.
[EDIT] Now my algorithm should arbitrarily set the size and position of each word and just put them there. How can I check if every word I put does not intersect with each other and with a photograph?
Link: http://www.imagechef.com/ic/word_mosaic/