Create png file and draw string in PHP

Description

The following code shows how to create png file and draw string.

Example


<?php/*ww w.j  av  a 2  s.c om*/
    $animage = imagecreate (200, 200);
    $red = imagecolorallocate ($animage, 255, 0, 0);
    imagerectangle ($animage, 0, 0, 200, 200, $red);
    $black = imagecolorallocate ($animage, 0, 0, 0);
    imagefilledellipse($animage, 100, 100, 150, 150, $black);
    $white = imagecolorallocate ($animage, 255, 255, 255);
    imagestring($animage, 5, 48, 95, "Hello World!", $white);
    imagepng ($animage);
    header ("Content-type: image/png");
    imagedestroy ($animage);
?>

The code above generates the following result.

Create png file and draw string in PHP




















Home »
  PHP Tutorial »
    Image »




Color
Create
Font
Operation
Shape
Text