PHP Imagettftext每个单词作为单独的图像

When using imagettftext I can create a single line of text as one long image using imagecreatetruecolor:

// Create the image
$im = imagecreatetruecolor(400, 30);

This will display as much text in a single line as will fit in the dimensions 400x30px.

How can I separate each word into a new image?

I'd like each new word image next to the one before (perhaps with space between) and then to wrap to the container size.

Would it also be possible for it to wrap to the new dimensions of the page after the browser is resized? That sounds ambitious, but would be really handy!

Any help is greatly received.

First off, I can't come up with a reason for someone to generate a new image for every word in a string as it would take a long time to do and require lots of server resources.

But to answer your question, you should probably do some sort of a loop, here's a quick mockup.

<?php
    $string = "This is a string with spaces";

    foreach(explode(" ",$string) as $word){
    // Image generation code here
    }
?>