Created
November 13, 2011 11:18
-
-
Save syohex/1361997 to your computer and use it in GitHub Desktop.
Get RGB and alpha and HSV from image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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