出力するGIF画像データをスクリプト内に入れておく
画像を表示するCGIファイルの記述例 (img_out.cgi)
出力例
参考:画像データのダンプスクリプト
この方が速いわけです・・・。
#!パールのパス
# 画像データを定義
my @data = (
0x47,0x49,0x46,0x38,0x39,0x61,0x0a,0x00,0x0a,0x00,
0x80,0xff,0x00,0x00,0xff,0x00,0xcc,0x00,0xcc,0x21,
0xf9,0x04,0x01,0x00,0x00,0x01,0x00,0x2c,0x00,0x00,
0x00,0x00,0x0a,0x00,0x0a,0x00,0x00,0x02,0x12,0x8c,
0x8f,0x07,0x89,0xb0,0x1c,0x9c,0x7c,0xe6,0xb9,0x66,
0xf1,0x84,0x91,0x32,0xcf,0x05,0x05,0x00,0x3b);
# 出力(こういうときはたいがいキャッシュしない)
print "Content-type: image/gif\n";
print "Cache-Control: no-cache\n";
print "Expires: 01/01/1970 00:00:00 GMT\n";
print "\n";
foreach (@data) {
print pack('C*', $_);
}
exit;
<img src="./img_out.cgi" border=0 width=10 height=10 alt="画像出力例">
↓
my $path_file = '取り込む画像のパス';
open(BIN, $path_file) or exit;
binmode(BIN);
my $buf;
read(BIN, $buf, -s $path_file);
close(BIN);
my $len = length($buf);
my $i;
print "\@data = (\n";
for ($i = 0; $i < $len; ++$i) {
printf("0x%02x", ord(substr($buf, $i, 1)));
if ($i == $len - 1) {
print ');';
} elsif ($i % 10 == 9) {
print ",\n";
} else {
print ',';
}
}