画像合成アクセスカウンター
<?php $dir = "../../sample/img/no/"; // 画像保存先フォルダ if($file = fopen("./dat/count.dat", "r+")) { // ファイルを開く flock($file, LOCK_EX); // ファイルロック $count = fgets($file); // カウント読み込み $count++; // カウント+1 rewind($file); // ポインタを先頭に fputs($file, $count); // ファイル書き込み flock($file, LOCK_EX); // ファイルロック解除 fclose($file); // ファイルを閉じる } $count = sprintf("%07d", $count); // 表示桁数調整 $len = strlen($count); // カウント桁数 for($i = 0 ; $i < $len ; $i++) { $imgfile = $dir . substr($count, $i, 1) . ".gif"; // 数字画像 $img[$i] = ImageCreateFromGIF($imgfile); // 数字画像読み込み list($w[$i], $h[$i]) = GetImageSize($imgfile); // 数字画像縦横サイズ $width += $w[$i]; // 生成画像横サイズ if($h[$i] > $height) { $height = $h[$i]; // 生成画像縦サイズ } } $image = ImageCreate($width, $height); // 画像生成 $bgcolor = imagecolorallocate($image, 240, 240, 240); // 背景色 $black = ImageColorAllocate($image, 0, 0, 0); $left = 0; // 画像合成位置 for($i = 0 ; $i < $len ; $i++) { ImageCopy($image, $img[$i], $left, 0, 0, 0, $w[$i], $h[$i]); // 画像合成 ImageDestroy($img[$i]); // 数字画像破棄(メモリ解放) $left += $w[$i]; // 次の画像合成位置 } ImageRectangle($image, 0, 0, $width - 1, $height - 1, $black); // 枠表示 Header("Content-Type: image/gif"); ImageGIF($image); // カウンタ画像表示 ImageDestroy($image); // カウンタ画像破棄(メモリ解放) ?>
〔 実行する 〕