1

I am trying to create a text overlay on an image using php and iMagick. The crucial part is that I want the text size to scale to fill a predefined box, so I do not want to set a fixed font size. I have found the code at ImageMagick - Text into rectangle but need to adapt this code for the iMagick. I seem to be able to do everything except the crucial part -size ${width}x100

Here's the code I have, with a few things that I have tried commented out

$draw = new ImagickDraw();
$draw->setGravity (Imagick::GRAVITY_SOUTHEAST);
$draw->setFont('Bookman-DemiItalic');
//$draw->setFontSize( 30 ); // don't want to set a fixed font size
$draw->setTextUnderColor('#00000075'); 
//$draw->setSize(0, 0, 200, 200); // error: Call to undefined method ImagickDraw::setSize() 
//$draw->setViewBox(200, 200, 800, 800); // appears to do nothing
//$draw->rectangle(200,200,300,300); // this just draws a separate white box
$draw->annotation(100, 100, 'The quick brown fox jumps over the lazy dog');  // works, but it's a default (small) text size and the box simply fits the exact  text with no border
$img->drawImage($draw);

Is there a size option that somehow I've missed in the docs?

Note that How can I wrap text using Imagick in PHP so that it is drawn as multiline text? partially addresses this issue, but it doesn't appear to offer scaling of the text to fit a fixed size box, rather a wrapping of text if the selected font size would cause the text to overrun. Though maybe I have misunderstood - I will give it a try!

Community
  • 1
  • 1
jamesinealing
  • 570
  • 8
  • 20
  • possible duplicate of [How can I wrap text using Imagick in PHP so that it is drawn as multiline text?](http://stackoverflow.com/questions/5746537/how-can-i-wrap-text-using-imagick-in-php-so-that-it-is-drawn-as-multiline-text) – cmorrissey Apr 15 '15 at 13:55
  • http://stackoverflow.com/questions/7891013/how-do-i-change-the-color-of-a-caption-drawn-with-php-imagicks-newpseudoimage-f – Mark Setchell Apr 15 '15 at 22:52
  • @cmorrissey thanks - I've updated the question to explain why I don't think that it's a direct duplicate – jamesinealing Apr 16 '15 at 21:17
  • @MarkSetchell thanks, but that method seems to also rely on setting a fixed font size, which is not what I want. Unless I've misunderstood. – jamesinealing Apr 16 '15 at 21:18

0 Answers0