PHP imagesetpixel() function

In this chapter you will learn:

  1. What is PHP imagesetpixel() function
  2. Syntax for PHP imagesetpixel() function
  3. Parameter for PHP imagesetpixel() function
  4. Return value for PHP imagesetpixel() function
  5. Example - imagesetpixel() example

Description

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 /*from   j ava 2 s  . c  om*/
        $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 ); 
?> 

Next chapter...

What you will learn in the next chapter:

  1. Description for PHP imagettftext() function
  2. Syntax for PHP imagettftext() function
  3. Parameters for PHP imagettftext() function
  4. Example - Draw text
Home » PHP Tutorial » PHP Image Functions
PHP imagearc() function
PHP imagecreate() function
PHP imagecreatetruecolor () function
PHP imageellipse() function
PHP imagefilledarc() function
PHP imageline() function
PHP imagepolygon() function
PHP imagerectangle() function
PHP imagesetpixel() function
PHP imagettftext() function