Set pixel in PHP

Description

The following code shows how to set pixel.

Example


<?php/* www. j  ava 2s  .  c  o  m*/
    $width = 255;
    $height = 255;
    $image = imagecreatetruecolor($width, $height);

    for ($i = 0; $i <= $width; ++$i) {
            for ($j = 0; $j <= $height; ++$j) {
                    $col = imagecolorallocate($image, 255, $i, $j);
                    imagesetpixel($image, $i, $j, $col);
            }
    }

    header("Content-type: image/png");
    imagepng($image);
    imagedestroy($image);
?>

The code above generates the following result.

Set pixel in PHP




















Home »
  PHP Tutorial »
    Image »




Color
Create
Font
Operation
Shape
Text