title: PHP Imagick function to add a label
body: <p>I found an imagemagick convert command <a href="https://stackoverflow.com/questions/39764846/imagemagick-best-fit-text-within-rectangle">here</a> to fit text into a smaller box, namely</p>
  <pre><code>convert sea.jpg \( -size 173x50 -background none label:&quot;A&quot; -trim -gravity center -extent 173x50 \) -gravity northwest -geometry +312+66 -composite result.png
  </code></pre>
  <p>I'm trying to replicate this in PHP using <a href="https://www.php.net/manual/en/class.imagick.php" rel="nofollow noreferrer">the IMagick library</a>
  However, I can't seem to find a way to add a label? The <a href="https://www.php.net/manual/en/imagick.labelimage.php" rel="nofollow noreferrer">IMagick LabelImage function</a> doesn't actually add a label on the image but only the metadata.</p>
  <p>my current attempt got me so far:</p>
  <pre><code>    $label = new Imagick();
      $label-&gt;newImage(173,50,new ImagickPixel('transparent'),&quot;png&quot;);
      $label-&gt;labelImage(&quot;Testing 123&quot;);
      $label-&gt;trimImage(0);
      $label-&gt;setGravity(imagick::GRAVITY_CENTER);
  </code></pre>
  <p>However the labelImage, as said, doesn't actually add anything to the image, so I think I've hit a dead end.
  What would be a good way to add a label to an image, or in general are there better ways to add text to an image in a shrink-to-fit way in a box using the IMagick library?</p>
  <p>Thanks in advance :)</p>