欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

做一张xbm图片_PHP

程序员文章站 2022-06-13 13:46:20
...
xbm是一种简单的双色图片位图格式,在早期的cgi中运用较多,目前多用于计数器上
setXBM(1234567890,0);

function setXBM($num,$mode=0) {
settype($num,"string");
$mode = $mode?0xff:0x00;
$int_width = strlen($num); //位数
$count_width=8; //单个数字宽度
$count_height=16; //高度

$bitmap = array(
0 => array(0xff, 0xff, 0xff, 0xc3, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0xc3, 0xff, 0xff, 0xff),
1 => array(0xff, 0xff, 0xff, 0xcf, 0xc7, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xff, 0xff, 0xff),
2 => array(0xff, 0xff, 0xff, 0xc3, 0x99, 0x9f, 0x9f, 0xcf, 0xe7, 0xf3, 0xf9, 0xf9, 0x81, 0xff, 0xff, 0xff),
3 => array(0xff, 0xff, 0xff, 0xc3, 0x99, 0x9f, 0x9f, 0xc7, 0x9f, 0x9f, 0x9f, 0x99, 0xc3, 0xff, 0xff, 0xff),
4 => array(0xff, 0xff, 0xff, 0xcf, 0xcf, 0xc7, 0xc7, 0xcb, 0xcb, 0xcd, 0x81, 0xcf, 0x87, 0xff, 0xff, 0xff),
5 => array(0xff, 0xff, 0xff, 0x81, 0xf9, 0xf9, 0xf9, 0xc1, 0x9f, 0x9f, 0x9f, 0x99, 0xc3, 0xff, 0xff, 0xff),
6 => array(0xff, 0xff, 0xff, 0xc7, 0xf3, 0xf9, 0xf9, 0xc1, 0x99, 0x99, 0x99, 0x99, 0xc3, 0xff, 0xff, 0xff),
7 => array(0xff, 0xff, 0xff, 0x81, 0x99, 0x9f, 0x9f, 0xcf, 0xcf, 0xe7, 0xe7, 0xf3, 0xf3, 0xff, 0xff, 0xff),
8 => array(0xff, 0xff, 0xff, 0xc3, 0x99, 0x99, 0x99, 0xc3, 0x99, 0x99, 0x99, 0x99, 0xc3, 0xff, 0xff, 0xff),
9 => array(0xff, 0xff, 0xff, 0xc3, 0x99, 0x99, 0x99, 0x99, 0x83, 0x9f, 0x9f, 0xcf, 0xe3, 0xff, 0xff, 0xff)
);

echo "#define counter_width " .($count_width * $int_width)."\r\n";
echo "#define counter_height " .$count_height. "\r\n";
echo "static unsigned char counter_bits[] = {\r\n";
for($i=0; $i for($j = 0; $j printf("0x%2x, ",$bitmap[$num[$j]][$i]^$mode);
}
}
echo "\r\n};";
}
?>