phpgdlib

PHP text to image


I got good result in PHP/GD to write text to image template, text wraps fine but is not "smooth", here is the code I am using:

<?php

header("Content-type: image/png");

$text = "go to school go to school go to school go to school go to school go to school go to school go to school go to school go to school go to school ";
$arrText=explode("\n",wordwrap($text,60,"\n"));

$im = imagecreatefrompng("template.png");
$y = 15; //vertical position of text
foreach($arrText as $arr)
{
    $white = imagecolorallocate($im,0,0,0); //sets text color
    imagestring($im,5,15,$y,trim($arr),$white); //create the text string for image,added     trim() to remove unwanted chars
    $y = $y+20;

}
imagepng($im);
imagedestroy($im);
?>

Solution

  • Try turning on anti-aliasing:

    imageantialias($im, true);
    

    Does that make it look any better?

    Or else try imagettftext with a truetype font:

    imagettftext ( $im, 15, 0, 15, $y, $white, 'fontfile.ttf', trim($arr));