用PHP做一张xbm图片

发表于:2007-07-14来源:作者:点击数: 标签:
xbm是一种简单的双色图片位图格式,在早期的cgi中运用较多,目前多用于计数器上 ? php setXBM(1234567890,0); function setXBM($num,$mode=0) { settype($num,string); $mode = $mode?0xff:0x00; $int_width = strlen($num);//位数 $count_width=8;//单个数
xbm是一种简单的双色图片位图格式,在早期的cgi中运用较多,目前多用于计数器上
<?php
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<$count_height; ++$i) {
    for($j = 0; $j < $int_width; ++$j) {
      printf("0x%2x, ",$bitmap[$num[$j]][$i]^$mode);
    }
  }
  echo "\r\n};";
}
?>

原文转自:http://www.ltesting.net