PHP imagesetpixel() function
In this chapter you will learn:
- What is PHP imagesetpixel() function
- Syntax for PHP imagesetpixel() function
- Parameter for PHP imagesetpixel() function
- Return value for PHP imagesetpixel() function
- 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:
- Description for PHP imagettftext() function
- Syntax for PHP imagettftext() function
- Parameters for PHP imagettftext() function
- Example - Draw text
Home » PHP Tutorial » PHP Image Functions