title: How to account for font swash with PHP and GD
body: <p>I have the following code to print text on an image. I am also adding a debug box around the text. However, I noticed the text on the left lies outside of the box that PHP gives me with <code>imagettfbbox</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/n2WNQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n2WNQ.png" alt="enter image description here"></a></p>
  
  <p>This looks like an issue with the font swash. Is there anyway to account for this? Can I figure out the distance between the start of the swash and the actual position <code>imagettfbbox</code> gives to me?</p>
  
  <p>I don't think this is an issue with the font, as I tried it with a few script style fonts and the results were similar.</p>
  
  <pre><code>&lt;?php
  
  $font       = 'scriptin.ttf';
  $text       = 'Ipsum';
  $size       = 30;
  $image      = imagecreatetruecolor(200, 200);
  $fontColour = imagecolorallocate($image, hexdec('11'), hexdec('11'), hexdec('11'));
  $bgColour   = imagecolorallocate($image, hexdec('CC'), hexdec('CC'), hexdec('CC'));
  
  imagefilledrectangle($image, 0, 0, 200, 200, $bgColour);
  
  $dimensions = imagettfbbox($size, 0, $font, $text);
  imagefilledrectangle(
      $image,
      $dimensions[0] + 40,
      $dimensions[7] + 50,
      $dimensions[2] + 40,
      $dimensions[3] + 50,
      imagecolorallocate($image, mt_rand(1, 180), mt_rand(1, 180), mt_rand(1, 180))
  );
  
  imagettftext(
      $image,
      $size,
      0,
      40,
      50,
      $fontColour,
      $font,
      $text
  );
  
  header('Content-Type: image/png');
  imagepng($image);
  </code></pre>
  
  <p>The code and font is available here: <a href="https://github.com/AydinHassan/image-swash-example" rel="nofollow noreferrer">https://github.com/AydinHassan/image-swash-example</a></p>
  
  <p>If you point a VHOST at the repository, you can just hit <code>swash.php</code></p>