PHP | Imagick getImagePixelColor() Function
Last Updated :
26 Nov, 2019
The Imagick::getImagePixelColor() function is an inbuilt function in PHP which is used to returns the color of a specified pixel.
Syntax:
ImagickPixel Imagick::getImagePixelColor( int $x, int $y )
Parameters:This function accepts two parameters as mentioned above and described below:
- $x: It specifies the x-coordinate of pixel.
- $y: It specifies the y-coordinate of pixel.
Return Value: This function returns an ImagickPixel instance for the color at the given coordinates.
Errors/Exceptions: This function throws ImagickException on error.
Below programs illustrate the Imagick::getImagePixelColor() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$colorPixel = $imagick ->getImagePixelColor(300, 90);
$color = $colorPixel ->getColorAsString();
echo $color ;
?>
|
Output:
srgb(231, 245, 234)
Program 2:
<?php
$imagick = new Imagick(
$colorPixel = $imagick ->getImagePixelColor(0, 0);
$color = $colorPixel ->getColorAsString();
echo $color ;
?>
|
Output:
srgb(255, 255, 255)
Reference: https://www.php.net/manual/en/imagick.getimagepixelcolor.php
Share your thoughts in the comments
Please Login to comment...