Reputation: 50832
How can I do the same as the following command line command in Perl using the ImageMagick API?
convert scotland.jpg[1x1+0+0] -depth 8 txt:
The result should look similar to this:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: ( 48, 50, 47) #30322F rgb(48,50,47)
Upvotes: 0
Views: 171
Reputation: 54323
I found an explanation in Perl & Image::Magick, getting color values by pixel and lifted/changed the code. This works for me:
use strict; use warnings;
use Data::Dumper;
use Image::Magick;
my $img = Image::Magick->new;
$img->Read("foo.jpg");
my @pixel = $img->GetPixels(
width => 1,
height => 1,
x => 0,
y => 0,
map => "RGB"
);
print Dumper \@pixel;
As said by brian in his answer to the linked question, you may need to reduce the depth. See the other question for details.
Upvotes: 1