Draw string on png image in PHP
Description
The following code shows how to draw string on png image.
Example
<?php//from ww w .j a v a 2 s . c o m
define("WIDTH", 300);
define("HEIGHT", 100);
$img = imagecreate(WIDTH, HEIGHT);
$white = imagecolorallocate($img, 255,255,255);
$black = imagecolorallocate($img, 0,0,0);
imagerectangle($img, 0, 0, WIDTH-1, HEIGHT-1, $black);
$start_x = 10;
$start_y = 10;
for($font_num = 1; $font_num <= 5; $font_num++) {
imagestring($img, $font_num, $start_x,$start_y, "Font #$font_num", $black);
$start_y += 15;
}
header("Content-type: image/png");
imagepng($img);
?>
The code above generates the following result.