Domanda

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?

È stato utile?

Soluzione

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)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top