title: center align text in image using php
body: <p>I am trying to do center align text in image using php, i have managed to make it right aligned properly but how can i make text center aligned... Please check code for right aligned text...</p>
  
  <pre><code>    $black = imagecolorallocate($image, 0, 0, 0);
  
      $dimensions = imagettfbbox(24, 0, 'arial.ttf', 'Test Heading');
      $textWidth = abs($dimensions[4] - $dimensions[0]);
      $x = imagesx($image) - $textWidth - 20; //add -20 to give right margin
      imagefttext($image, 24, 0, $x, 40, $black, 'arial.ttf', 'Test Heading');
  </code></pre>
  
  <p>How can i make text center aligned, any help. thanks</p>