I have cobbled together the following code, which very nearly works:
<?php
$img = new Imagick("quote_blank.jpg");
$txt = new Imagick();
$txt->setBackgroundColor("transparent");
$txt->newPseudoImage(380,250, "Caption:".htmlspecialchars($_GET['quote']) );
$txt->colorizeImage('#468847',1);
$img->compositeImage($txt, imagick::COMPOSITE_OVER, 10, 80);
$draw = new ImagickDraw();
$draw->setFillColor('#468847');
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
$draw->setFontSize(25);
$draw->setFontStyle(3);
$img->annotateImage($draw, 5,5,0, htmlspecialchars($_GET['attrib']) );
$img->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $img;
?>
(please note that quote_blank.jpg is a 400x400 image background over which the text is rendered and resides in the same directory as the php file).
The issue is that the caption only fills the 380x250 PseudoImage with a very small number of short words. Anything of any length results in just the top half (or less) of the box having any text in it (aside from the attribution annotation).
It seems like the PseudoImage is working correctly but that ImageMagick's algorithm for calculating the font size is only designed to fill the width, not the height. I have no idea how it decides what line length to go for (which would presumably in turn dictate the font size and therefore number of lines and vertical coverage of the caption box).
So I guess my question is this: Is there any way of changing how it does it's calculations in order to fill as much of the caption box as possible, horizontal AND vertical?
Sample of just a few words, showing the caption can go full-height:
Sample of a more typical length of text, showing it doesn't fill the box vertically
I tested your code with ImageMagick 6.8.9-8 and got the following output, which is better than what you're getting. If you're using an older version, try updating ImageMagick.