Skip to content

Instantly share code, notes, and snippets.

@syohex
Created November 13, 2011 11:18
Show Gist options
  • Save syohex/1361997 to your computer and use it in GitHub Desktop.
Save syohex/1361997 to your computer and use it in GitHub Desktop.
Get RGB and alpha and HSV from image
#!perl
use strict;
use warnings;
use Imager;
my $file = shift or die "Usage: $0 image";
my $img = Imager->new(file => $file) or die Imager->errstr;
my ($width, $height) = ($img->getwidth, $img->getheight);
for my $x (0..($width-1)) {
for my $y (0..($height-1)) {
my $color = $img->getpixel(x => $x, y => $y);
my ($r, $g, $b, $alpha) = $color->rgba;
my ($h, $s, $v) = $color->hsv;
print "($x, $y) => RGBA($r, $g, $b, $alpha) ";
print ", HSV($h, $s, $v)\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment