Question

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);
?>
Was it helpful?

Solution

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

OTHER TIPS

use :

$font = dirname(__FILE__)."/arial.ttf";
imagettftext($template, 20, 0, 100, 50, $white, $font, 'Some text');

I have just fixed this issue by replacing TTF file with a new one. The old file got corrupted after a server migration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top