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.
Vinicius Pinto had the right answer right off the bat. But updating wasn't so easy on a shared server- I have not figured out how to get Imagick to use the updated version. So I had to rewrite my code to access ImageMagick via the commandline, which I wanted to share. Code doesn't show up well as far as I can tell on a comment, so sorry for cheating the answer feature a little.
$location='/home/user/local/bin/convert';
$command='convert -background none -size 380x250 -fill "#468847" caption:"'.htmlspecialchars($_GET['quote']).'" quote_blank.jpg +swap -gravity southeast -geometry +10+80 -composite convert -fill "#468847" -gravity southeast -pointsize 25 -annotate 0x20+5+5 "'.htmlspecialchars($_GET['attrib']).'" anno_label.jpg';
exec ($location . ' ' .$command);
header('Content-Type: image/jpeg');
readfile('anno_label.jpg');
unlink('anno_label.jpg');