Search code examples
phpfontsgdrenderimagettftext

Filled rectangles instead of text while using imagettftext


I have some problems with rendering text using imagettftext(); Somehow it just shows filled rectangles. No errors at all. http://postimage.org/image/k61c8xi0n/

  • PHP Version: 5.3.8
  • GD Support: Enabled
  • GD Version: bundled (2.0.34 compatible)
  • Freetype Support: Enabled
  • Freetype linkage: With freetype
  • Freetype Version: 2.4.3

Here's the code, nothing strange. Font path works.

<?php 
header("Content-type: image/png");
$template = imagecreatefrompng("template.png");

imagealphablending( $template, false );
imagesavealpha( $template, true );

$white = imagecolorallocate($template, 255, 255, 255);
imagettftext($template, 20, 0, 100, 50, $white, 'arial.ttf', 'Some text');

imagepng($template);
?>

Solution

  • Using your code, if I set imagealphablending to true (or comment it out) it works fine.