title: imagecreatefrompng() + imagettftext() low quality text - how to anti alias
body: <p>Take the following base image (PNG-24):</p>
  
  <p><img src="https://i.stack.imgur.com/Jh0Do.png" alt="enter image description here"></p>
  
  <p>We're trying to write text to the image as follows:</p>
  
  <pre><code>&lt;?
  ini_set('display_errors', 1); 
  error_reporting(E_ALL);
  
  //#### Load the base image
  $im = imagecreatefrompng("images/SpecialClearanceBlank.png");
  imagealphablending($im, false);
  imagesavealpha($im, true);
  
  //#### Create the badge
  if($im) {
      //#### define some colours to use with the image
      $white = imagecolorallocate($im, 255, 255, 255);
  
      //#### get the width and the height of the base image
      $width = imagesx($im);
      $height = imagesy($im);
  
      //#### Define font and text
      $font = "/var/www/arial.ttf";
      $fontSize = 13;
      $angle = 0;
      $text = "15%";
  
      //#### calculate the left position of the text:
      $dimensions = imagettfbbox($fontSize, $angle, $font, $text);
      $textWidth = abs($dimensions[4] - $dimensions[0]);
      $leftTextPos = ( $width - $textWidth ) / 2;
  
      //#### finally, write the string:
      //imagestring($im, 5, $leftTextPos, $topTextPos, $text, $white);
      imagettftext($im, $fontSize, $angle, $leftTextPos + 1, 29, $white, $font, $text);
  
      // output the image
      // tell the browser what we're sending it
      Header('Content-type: image/png');
      // output the image as a png
      imagepng($im);
  
      // tidy up
      imagedestroy($im);
  }
  
  ?&gt;
  </code></pre>
  
  <p>This is producing low quality text (very blocky) - how would one anti alias the text so it looks smooth?</p>
  
  <p>This is the blocky version:</p>
  
  <p><img src="https://i.stack.imgur.com/MwISu.png" alt="enter image description here"></p>
  
  <p>Upon closer analysis of the rendered png (magnified in photoshop) i can see that the text i am writing has no anti aliasing and the pixels being written are almost transparent?</p>
  
  <p>What is causing this - how do i get smooth text?</p>
  
  <p><img src="https://i.stack.imgur.com/sbJ3B.jpg" alt="enter image description here"></p>