Create different color and use it to fill rectangle in PHP

Description

The following code shows how to create different color and use it to fill rectangle.

Example


<?php/*from w w w.j av a2 s. c  o  m*/
        define("WIDTH", 300);
        define("HEIGHT", 300);

        $img = imagecreatetruecolor(WIDTH, HEIGHT);

        $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
        $yellow = imagecolorallocate($img, 0xFF, 0xFF, 00);
        $red = imagecolorallocate($img, 0xFF, 0, 0);
        $blue_t   = imagecolorallocatealpha($img, 0, 0, 0xFF, 0x40);

        imagefill($img, 1, 1, $white);

        imageline($img, 0,0, WIDTH-1, HEIGHT-1, $blue_t);

        imagefilledrectangle($img, (WIDTH/2)-50, (HEIGHT/2)-50,(WIDTH/2)+50, (HEIGHT/2)+50, $yellow);

        header("Content-Type: image/png");
        imagepng($img);

?>

The code above generates the following result.

Create different color and use it to fill rectangle in PHP




















Home »
  PHP Tutorial »
    Image »




Color
Create
Font
Operation
Shape
Text