title: Center text on image using PHP GD
body: <p>So I am creating a banner generator.</p>
  
  <p>I will be adding text in the middle, but would like it to be exactly in the center.
  I know that <code>imagettftext</code> can be used to write onto the banner, but that won't center it.</p>
  
  <p>A likely solution could be to find the width of the text and then use half of it taken away from half of the banner width, but I've got no idea about how to do this.</p>
  
  <p>I am using PHP-GD and do not want to use anything else I will have to install.</p>
  
  <pre><code>imagettftext($img, 14, 0, (468 - ((strlen($_GET['description']) * imagefontwidth(imageloadfont('minecraft.ttf'))) / 1)), 85, imagecolorallocate($img, 0, 0, 0), 'minecraft.ttf', $_GET['description']);
  </code></pre>
  
  <p>The code above is making the result above. It is fine with small strings but there must be something wrong since as soon as they become long, it fails.</p>