Draw string with different color in PHP

Description

The following code shows how to draw string with different color.

Example


<?php/*w w w  . j  av  a2s  . com*/
    $animage = imagecreate (500, 500);
    $white = imagecolorallocate ($animage, 255, 255, 255);
    $black = imagecolorallocate ($animage, 0x00, 0x00, 0x00);
    imagefilledrectangle ($animage, 0, 0, 500, 500, $black);
    $blue = imagecolorallocate ($animage, 0, 0, 255);
    $green = imagecolorallocate ($animage, 0, 255, 0);
    $title = "title";
    imagestring ($animage, 4, 50, 5, $title, $blue);
    $copy = "information";
    imagestring ($animage, 4, 100, 25, $copy, $green);
      
    imagepng ($animage);
    header ("Content-type: image/png");
    imagedestroy ($animage);
?>

The code above generates the following result.

Draw string with different color in PHP




















Home »
  PHP Tutorial »
    Image »




Color
Create
Font
Operation
Shape
Text