Home Tutorial Php Phpgd PHP GD image set pixel

 
 

Share on Google+Share on Google+
PHP GD image set pixel
Posted on: November 11, 2009 at 12:00 AM
Advertisement
This example shows how to set the pixel of an image in php gd.

<?php

$x = 200;

$y = 200;

$gd = imagecreatetruecolor($x, $y);

$corners[0] = array('x' => 100, 'y' => 10);

$corners[1] = array('x' => 0, 'y' => 190);

$corners[2] = array('x' => 200, 'y' => 190);

$red = imagecolorallocate($gd, 255, 255, 255);

for ($i = 0; $i < 100000; $i++) {

imagesetpixel($gd, round($x),round($y), $red);

$a = rand(0, 2);

$x = ($x + $corners[$a]['x']) / 2;

$y = ($y + $corners[$a]['y']) / 2;

}

header('Content-Type: image/png');

imagepng($gd);

?>

After running the program you will get the following output

Advertisement

Related Tags for PHP GD image set pixel:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 11, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com