2

Is it possible to get color of any picture pixel with PHP Gmagick extension?

In IMagick I can get this info from getImagePixelColor method:

$color = $img->getImagePixelColor($x, $y)->getColor();

How to get this result via GMagick?

Andy Al
  • 29
  • 5

1 Answers1

4

There isn't currently a native method to do this with Gmagick. This will get the job done though:

$img_clone = clone $img;    // No need to modify the original object.
$img_clone->cropImage(1, 1, $x, $y);
$color = $img_clone->getImageHistogram()[0]->getColor();

Returns

(string) rgb(0,0,0)
Isius
  • 6,712
  • 2
  • 22
  • 31