I try to get the pixel at a coordinate in a image. I have the following working in PHP, but unfortunately my current setup only allows to use EXEC access to ImageMagick.
How would these lines look as an exec command
$img = new Imagick('test2.jpg');
$pixel = $img->getImagePixelColor(10, 10);
$target = $pixel->getColorAsString();
Thanks
For CLI command, user the -format
operator to read color information.
convert test2.jpg -format '%[pixel:p{10,10}]' info:-
See Accessing Pixels section in the FX document, and Format & Print Image Properties.
An explanation:
%[pixel: ] <= Evaluate a pixel color by FX expression
p{10,10} <= An FX expression to specify an absolute position
You can also simplify the above example by using the identify
utility
identify -format '%[pixel:p{10,10}]' test2.jpg