士多啤梨 Perl- # Strawberry Perl 5.24
- use Imager;
- use File::Basename qw/basename/;
- my $threshold = 10000;
- my ($colors, $newname);
-
- for my $f (glob "*.jpg")
- {
- next if $f =~/C\.jpg/; # 如果已经改名就跳过
- $colors = count_color($f); # 获取颜色计数
- printf "%6d %s %s\n", $colors, $f, $colors > $threshold ? "Colorful" : "";
- if ( $colors > $threshold )
- {
- $newname = $f;
- $newname=~s/(\.jpg)$/C$1/;
- rename $f, $newname;
- }
- }
-
- sub count_color
- {
- my $file = shift;
- my $img = Imager->new(file=>$file) or die Imager->errstr();
- return $img->getcolorcount();
- }
复制代码 输出示例- 19326 000005.jpg Colorful
- 4156 000006.jpg
复制代码
|