0

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)
ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Thariama
  • 50,002
  • 13
  • 138
  • 166
  • You should make a list of the things this command does. Then you can go and look that up at http://www.imagemagick.org/script/perl-magick.php and apply all the things you need. – simbabque Sep 14 '12 at 09:08
  • problem is, i am not that much into perlmagick to know what this command does exactly, but i know how to parse the result in order to get the pixel color of the first pixel in my image (that is my goal) – Thariama Sep 14 '12 at 09:09
  • Do you want to use that in your Perl script, or do you need this text file? – simbabque Sep 14 '12 at 09:35
  • i want to use it in perl script – Thariama Sep 14 '12 at 09:41

1 Answers1

1

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.

Community
  • 1
  • 1
simbabque
  • 53,749
  • 8
  • 73
  • 136