#!/usr/bin/perl # # gif画像総ファイルの合計ドット数を算出する。 # 瞬間的に持てる画像の総ドット数をオーバーしてないか # 検討するために作成。 # # usage: perl getdotsize.pl 対象ディレクトリ use strict; use Image::Magick; # 瞬間的に持てるであろう画像総ドット数 my $limitsize = 240 * 240 * 6; if ( $#ARGV < 0 ) { print "usage: perl getdotsize.pl DIR_NAME\n"; exit; } my $dirname = $ARGV[0]; unless ( -d $dirname ) { print "Error : '$dirname' not found.\n"; exit; } my @flist = (); my @filelist = (); opendir DH, $dirname or die "$dirname : $!"; while ( my $file = readdir DH ) { next if $file =~ /^\.{1,2}$/; next unless $file =~ /\.(gif|GIF)$/; push( @flist, $file ); } closedir DH; @filelist = sort @flist; my @dotsizelist = (); print "\n"; foreach my $fn (@filelist) { my $img = Image::Magick->new; $img->Read("$dirname/$fn"); my ( $width, $height ) = $img->Get( 'width', 'height' ); print "$fn : $width x $height = ", $width * $height, "\n"; push( @dotsizelist, $width * $height ); undef $img; } my $alldotsize = 0; foreach (@dotsizelist) { $alldotsize += $_; } print "\n", '-' x 40, "\n"; print "All Dot Size = $alldotsize\n"; print "Limit Dot Size = $limitsize\n"; my $d = $alldotsize - $limitsize; if ( $alldotsize > $limitsize ) { my $w = 240; my $h = int( $d / $w ); print " !!! Over $d dot ( = $w x $h )\n"; } else { print " $d dot\n"; } exit;