Skip to content

Instantly share code, notes, and snippets.

@Likk
Last active August 29, 2015 14:27
Show Gist options
  • Save Likk/81b3946aa49e8bbae0f5 to your computer and use it in GitHub Desktop.
Save Likk/81b3946aa49e8bbae0f5 to your computer and use it in GitHub Desktop.
use GD and extract image for perl
sub image_extract {
my $gd_res = '';
my $file = shift;
my @def_rgb = (14, 16, 13);
my $gd = FromJpeg GD::Image->new($file);
my $dst = GD::Image->new(85, 30);
$dst->copy($gd, 0,0, 355, 265, 85, 30);
my ($ws, $we, $hs, $he) = (1,85, 2,30);
my $count = 1;
my @rgb = (0,0,0);
for my $x ($ws..$we){
for my $y ($hs..$he){
my $pic = $dst->getPixel($x,$y);
my @rgb_wk = $dst->rgb($pic);
$rgb[0] += $rgb_wk[0];
$rgb[1] += $rgb_wk[1];
$rgb[2] += $rgb_wk[2];
$count++;
}
}
for(@rgb){ $_ = int(($_ / $count) / 10)}
if( $def_rgb[0] == $rgb[0] or
$def_rgb[1] == $rgb[1] or
$def_rgb[2] == $rgb[2]){
$gd_res = 0;
}
else {
$gd_res = 1;
}
return $gd_res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment