سؤال

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?

هل كانت مفيدة؟

المحلول

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)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top