Created
June 11, 2013 10:49
-
-
Save JEEN/5756006 to your computer and use it in GitHub Desktop.
그림파일의 평균RGB 값 구하기
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use GD; | |
my $img = GD::Image->new($ARGV[0]); | |
my ($width, $height) = $img->getBounds; | |
my $n = 0; | |
my $avg = 0; | |
for my $y (0 .. $height - 1) { | |
for my $x (0 .. $width - 1) { | |
my ($r, $g, $b) = $img->rgb( $img->getPixel($x, $y)); | |
my $rgb = ($r << 16) + ($g << 8) + $b; | |
$avg = ($n * $avg + $rgb) / ($n + 1); | |
$n += 1; | |
} | |
} | |
printf "#%06X\n", $avg; | |
=pod | |
Usage: | |
perl average-color.pl [file] | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment