如何使用 ImageMagick getImagePixelColor 作为 exec 命令?

How to use ImageMagick getImagePixelColor as exec command?

我尝试获取图像中某个坐标处的像素。我在 PHP 中有以下工作,但不幸的是,我当前的设置只允许使用 EXEC 访问 ImageMagick。

这些行看起来像一个 exec 命令

$img = new Imagick('test2.jpg');
$pixel = $img->getImagePixelColor(10, 10);
$target = $pixel->getColorAsString();

谢谢

对于 CLI 命令,使用 -format 运算符读取颜色信息。

convert test2.jpg -format '%[pixel:p{10,10}]' info:-

Accessing Pixels section in the FX document, and Format & Print Image Properties

一个解释:

%[pixel:        ] <= Evaluate a pixel color by FX expression
        p{10,10}  <= An FX expression to specify an absolute position

您还可以使用 identify 实用程序

简化上述示例
identify -format '%[pixel:p{10,10}]' test2.jpg