PHP Tutorial - PHP imagesetpixel() function






imagesetpixel() draws a pixel at the specified coordinate.

Syntax

PHP imagesetpixel() function has the following syntax.

bool imagesetpixel ( resource $image , int $x , int $y , int $color )

Parameter

PHP imagesetpixel() function has the following parameters.

  • image - An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
  • x - x-coordinate.
  • y - y-coordinate.
  • color - A color identifier created with imagecolorallocate().




Return

Returns TRUE on success or FALSE on failure.

Example


<?php 
        $myImage = imagecreatetruecolor( 200, 100 ); 
        $myGray = imagecolorallocate( $myImage, 204, 204, 204 ); 
        $myBlack = imagecolorallocate( $myImage, 0, 0, 0 ); 
        imagesetpixel( $myImage, 120, 60, $myBlack );   
        header( "Content-type: image/png" ); 
        imagepng( $myImage ); 
        imagedestroy( $myImage ); 
?>