|
AnalizeJPG.pl(旧版 GetJPGsize.pl)
#!/usr/local/bin/perl
# (c)copyleft 2017-3-19 : Coded by shun kinoshita / knuhs
my $directory = "C:/・・・・・・・・・"; # 適宜書き替える
my $jpgFile1 = "・・・.JPG"; # 適宜書き替える
my $jpgFile2 = "・・・.JPG"; # 適宜書き替える
open(JPG, "$directory/$jpgFile1") || die "ファイルを開けません。: $!";
# 一括読み込み
$/ = undef(); $_ = <JPG>; $/ = '\n';
close(JPG);
# データへのリファランスを渡す
my ($W, $H) = GetJPGsize(\$_);
# 結果を出力する
print "$jpgFile1";
print "\nWidth:=$W, Height:=$H\n";
# 2度目以上はうまく動作しない。
# open(JPEG,"$directory/$jpgFile2")|| die "ファイルを開けません。: $!";
# $/ = undef(); $_ = <JPEG>; $/ = '\n';
# close(JPEG);
# ($W, $H) = GetJPGsize(\$_);
#
# print "$jpgFile2";
# print "\nWidth:=$W, Height:=$H\n";
exit;
################################################# sub GetJPGsize
{
my $FF=0xFF; #
my $C0=0xC0; #
my $D9=0xD9; #
my $SOI=0xFFD8; # SOI : Start Of Image
my $EOI=0xFFD9; # EOI : End Of Image
my $SOF=0xFFC0; # SOF : Segment Of Frame Header
my ($pos, $W, $H, $count) = (0, 0, 0, 0);
my $jpgRef = shift @_;
my $c;
# get (n) Byte
sub getByte
{ my $n = shift @_;
my $str ;
$str = unpack(($n==1)?"C":"n", substr($$jpgRef, $pos, $n)) ;
$pos += $n;
return ($str);
}
# start here
if( getByte(2) != $SOI ) # SOI : Start Of Image
{ print "JPGファイルではありません!\n"; return(0,0); }
while(1)
{ next if( getByte(1) != $FF );
$c = getByte(1);
return(-1,-1) if( $c == $D9 ); # EOI : End Of Image
next if( $c != $C0 ); # SOF : Segment Of Frame Header
$pos += 3; $H = getByte(2); $W = getByte(2); last;
}
return ($W, $H);
}
|
![](/cgi-bin/user/skinoshita/Count.cgi?df=cp03.count)
|
|
|