アクセスカウンター等でよく見る、数字の描かれた画像を連結して一枚の画像として表示する場合のソースです。
<?php
//カウント
$count = 12345;
//桁
$figure = 8;
//数字画像のサイズ
$width = 16;
$height = 24;
$count = sprintf("%0{$figure}d", $count);
$length = strlen($count);
$base = ImageCreateTrueColor($width * $length, $height);
for($i=0;$i<$length;$i++){
$num = substr($count, $i, 1);
$digit = ImageCreateFromJpeg("img/{$num}.jpg");
ImageCopy($base, $digit, $i * $width, 0, 0, 0, $width, $height);
imagedestroy($digit);
}
header("Content-Type: image/jpeg");
imagejpeg($base, NULL, 80);
imagedestroy($base);
今回は「1.jpg」のように数字がファイル名になっている統一サイズの画像を使いました。
先頭をゼロで埋める必要がない場合は sprintf の部分を消して下さい。

