GD PHP

Drawing Individual Pixels with GD

This PHP program demonstrates how to draw a gradient image by coloring individual pixels with the Graphics Draw, GD, library.

ColorGradient.php

<?php
$qMyImage = imagecreatetruecolor(256, 256);

for ($iX = 0; $iX < 256; ++$iX) {
	for ($iY = 0; $iY < 256; ++$iY) {
	    // Red, Green, Blue as integer values from 0 to 255
		$qPixelColor = imagecolorallocate($qMyImage, $iX, $iY, 255);
		imagesetpixel($qMyImage, $iX, $iY, $qPixelColor);
	}
}

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

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.