画像合成アクセスカウンター
#! /usr/local/bin/perl use Image::Magick; print qq(Content-type: image/jpeg\n\n); binmode(STDOUT); # 画像保存ディレクトリ $dir = "../../sample/img/no/"; # カウントの読み込み open(FILE, "+<./dat/count.dat"); eval{ flock(FILE, 2) }; $count = <FILE>; # カウントに1を加える ++$count; # カウントの書き込み seek(FILE, 0, 0); print FILE $count; close FILE; $count = sprintf("%07d", $count); # カウント桁数調整 # オブジェクト作成 $image = Image::Magick->new; # 数字画像(オブジェクト作成、サイズ取得) for($i = 0 ; $i < length($count) ; $i++) { my $file = $dir . substr($count, $i, 1) . ".gif"; # 数字画像ファイル名 $img[$i] = Image::Magick->new; $img[$i]->Read($file); # 数字画像読み込み ($w[$i], $h[$i]) = $img[$i]->Get('width', 'height'); # 数字画像サイズ取得 $size[0] += $w[$i]; # 生成画像横幅 if($size[1] < $h[$i]) { # 生成画像縦幅 $size[1] = $h[$i]; } } # 画像サイズ $imagesize = $size[0] . "x" . $size[1]; $image->Set(size=>$imagesize); # 画像読み込み(背景色) $image->Read('XC:#eeffee'); # 画像合成 $x = 0; $y = 0; for($i = 0 ; $i < length($count) ; $i++) { $image->Composite(image=>$img[$i], compose=>'Over', x=>$x, y=>$y); # 画像合成 undef $img[$i]; # 数字画像破棄 $x += $w[$i]; # 次の画像合成位置 } # 画像に枠 $image->Frame( geometry => '3x3', inner => 1, outer => 1 ); # 画像表示 $image->Write("gif:-"); exit;
〔 実行する 〕