Change colors with a loop and paint in PHP

Description

The following code shows how to change colors with a loop and paint.

Example


<?php// w w w. j ava 2s. c o  m
    $image = imagecreate(400,300);
    $gold = imagecolorallocate($image, 255, 240, 00);
    $white = imagecolorallocate($image, 255, 255, 255);
    $color = $white;

    for ($i = 400, $j = 300; $i > 0; $i -= 4, $j -= 3) {
            if ($color == $white) {
                    $color = $gold;
            } else {
                    $color = $white;
            }

            imagefilledrectangle($image, 400 - $i, 300 - $j, $i, $j, $color);
    }

    imagepng($image);
    imagedestroy($image);
?>




















Home »
  PHP Tutorial »
    Image »




Color
Create
Font
Operation
Shape
Text