PHP | imagesetpixel() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The imagesetpixel() function is an inbuilt function in PHP which is used to draw a pixel at the specified coordinate.Syntax: bool imagesetpixel( resource $image, int $x, int $y, int $color ) Parameters: This function accept four parameters as mentioned above and described below: $image: It specifies the image resource to work on.$x: It specifies the x-coordinate of pixel.$y: It specifies the y-coordinate of pixel.$color: It specifies the color of pixel.Return Value: This function returns TRUE on success or FALSE on failure. Below given programs illustrate the imagesetpixel() function in PHP: Program 1 (Drawing a line on a image): php <?php // Load the png image $image = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Draw a line using imagesetpixel $red = imagecolorallocate($image, 255, 0, 0); for ($i = 0; $i < 1000; $i++) { imagesetpixel($image, $i, 100, $red); } // Output image to the browser header('Content-type: image/png'); imagepng($image); ?> Output: Program 2 (Drawing a pattern): php <?php // Create a blank image 700x200 $image = imagecreatetruecolor(700, 200); $points = [ array('x' => 00, 'y' => 10), array('x' => 0, 'y' => 190), array('x' => 800, 'y' => 190) ]; // Prepare the color $green = imagecolorallocate($image, 0, 255, 0); // Draw the pattern $x = 700; $y = 200; for ($i = 0; $i < 100000; $i++) { imagesetpixel($image, round($x), round($y), $green); $a = rand(0, 2); $x = ($x + $points[$a]['x']) / 2; $y = ($y + $points[$a]['y']) / 2; } // Show the output in browser header('Content-Type: image/png'); imagepng($image); ?> Output: Reference: https://www.php.net/manual/en/function.imagesetpixel.php Comment More infoAdvertise with us Next Article PHP | imagesetpixel() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-image-functions Similar Reads PHP | imagesettile() Function The imagesettile() function is an inbuilt function in PHP which is used to set the tile image for filling the area. Syntax: bool imagesettile( $image, $tile ) Parameters: This function accepts two parameters as mentioned above and described below: $image: It is returned by one of the image creation 2 min read PHP | imagesx() Function The imagesx() function is an inbuilt function in PHP which is used to return the width of the given image. Syntax: int imagesx( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable can store the image created by imagecreatetruecolor() image cre 1 min read PHP | imagesetclip() function The imagesetclip() function is an inbuilt function in PHP which is used to set the current clipping rectangle, i.e. the area beyond which no pixels will be drawn. Syntax: bool imagesetclip( resource $im, int $x1, int $y1, int $x2, int $y2 ) Parameters:This function accepts five parameters as mention 2 min read PHP | imagesetstyle() function The imagesetstyle() function is an inbuilt function in PHP which is used to set the style to be used by all line drawing functions like imageline() or imagepolygon(). Syntax: bool imagesetstyle( resource $image, array $style ) Parameters:This function accepts two parameters as mentioned above and de 2 min read PHP | imagecreate() Function The imagecreate() function is an inbuilt function in PHP which is used to create a new image. This function returns the blank image of given size. In general imagecreatetruecolor() function is used instead of imagecreate() function because imagecreatetruecolor() function creates high quality images. 2 min read PHP | imagesy() Function The imagesy() function is an inbuilt function in PHP which is used to return the height of the given image. Syntax: int imagesy( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable store the image created by imagecreatetruecolor() image creati 1 min read PHP | imagesetthickness() Function The imagesetthickness() function is an inbuilt function in PHP which is used to set the thickness for line drawing. Syntax: bool imagesetthickness( $image, $thickness ) Parameters: This function accepts two parameters as mentioned above and described below: $image: It is returned by one of the image 2 min read PHP | getimagesize() Function The getimagesize() function in PHP is an inbuilt function which is used to get the size of an image. This function accepts the filename as a parameter and determines the image size and returns the dimensions with the file type and height/width of image. Syntax: array getimagesize( $filename, $image_ 2 min read PHP | imagepng() Function The imagepng() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to PNG and applying filters to the image. Syntax: bool imagepng( resource $image, int $to, int $qual 2 min read Like