Thursday, May 21, 2026
HomeLanguagesPHP | Imagick getImagePixelColor() Function

PHP | Imagick getImagePixelColor() Function

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
  
// Create a new imagick object
$imagick = new Imagick(
  
// Get the Pixel Color
$colorPixel = $imagick->getImagePixelColor(300, 90);
  
// Convert Pixel into Color
$color = $colorPixel->getColorAsString();
echo $color;
?>


Output:

srgb(231, 245, 234)

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Get the Pixel Color
$colorPixel = $imagick->getImagePixelColor(0, 0);
  
// Convert Pixel into Color
$color = $colorPixel->getColorAsString();
echo $color;
?>


Output:

srgb(255, 255, 255)

Reference: https://www.php.net/manual/en/imagick.getimagepixelcolor.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS