More servicesWindows Live
HomeHotmailSpacesOneCare
 
MSN
Sign in
 
 
Spaces home  骑士的生活PhotosProfileFriendsMore Tools Explore the Spaces community

骑士的生活

View spaceSend a message
Occupation:
Age:
Interests:
累的时候我喜欢睡觉、聊天、看卡通。

骑士的生活

2007年过去了,有点发胖。2008年要放纵一下,在进入三十前画个人生的感叹号!
Updated 5/8/2007
Updated 9/27/2006
Updated 6/15/2006
Updated 2/15/2006
Updated 1/13/2006
Updated 6/8/2005
Updated 5/17/2005
Updated 5/17/2005
January 29

[转] 用 PHP 怎么将BMP转成其它格式图片

从老外的坛子上扒下来的,刚刚测过,24位的bmp可以转,其它的没测
 
The GD library doesn't support .BMP files for some reason. I've
written a function that converts .BMP files to .GD, a very simple
format that GD uses.

The following code implements imagecreatefrombmp(). It first convert
the BMP to GD, saving it to a temporary location, then open the image
using imagecreatefromgd().


<?php
function ConvertBMP2GD($src, $dest = false) {
 if(!($src_f = fopen($src, "rb"))) {
  return false;
 }
 if(!($dest_f = fopen($dest, "wb"))) {
  return false;
 }
 $header = unpack("vtype/Vsize/v2reserved/Voffset", fread($src_f, 14));
 $info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant", fread($src_f, 40));
 extract($info);
 extract($header);
 if($type != 0x4D42) { // signature "BM"
  return false;
 }
 $palette_size = $offset - 54;
 $ncolor = $palette_size / 4;
 $gd_header = "";
 // true-color vs. palette
 $gd_header .= ($palette_size == 0) ? "\xFF\xFE" : "\xFF\xFF";
 $gd_header .= pack("n2", $width, $height);
 $gd_header .= ($palette_size == 0) ? "\x01" : "\x00";
 if($palette_size) {
  $gd_header .= pack("n", $ncolor);
 }
 // no transparency
 $gd_header .= "\xFF\xFF\xFF\xFF";
 fwrite($dest_f, $gd_header);
 if($palette_size) {
  $palette = fread($src_f, $palette_size);
  $gd_palette = "";
  $j = 0;
  while($j < $palette_size) {
   $b = $palette{$j++};
   $g = $palette{$j++};
   $r = $palette{$j++};
   $a = $palette{$j++};
   $gd_palette .= "$r$g$b$a";
  }
  $gd_palette .= str_repeat("\x00\x00\x00\x00", 256 - $ncolor);
  fwrite($dest_f, $gd_palette);
 }
 $scan_line_size = (($bits * $width) + 7) >> 3;
 $scan_line_align = ($scan_line_size & 0x03) ? 4 - ($scan_line_size & 0x03) : 0;
 for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) {
 // BMP stores scan lines starting from bottom
  fseek($src_f, $offset + (($scan_line_size + $scan_line_align) * $l));
  $scan_line = fread($src_f, $scan_line_size);
  if($bits == 24) {
   $gd_scan_line = "";
   $j = 0;
   while($j < $scan_line_size) {
    $b = $scan_line{$j++};
    $g = $scan_line{$j++};
    $r = $scan_line{$j++};
    $gd_scan_line .= "\x00$r$g$b";
   }
  }
  else if($bits == 8) {
   $gd_scan_line = $scan_line;
  }
  else if($bits == 4) {
   $gd_scan_line = "";
   $j = 0;
   while($j < $scan_line_size) {
    $byte = ord($scan_line{$j++});
    $p1 = chr($byte >> 4);
    $p2 = chr($byte & 0x0F);
    $gd_scan_line .= "$p1$p2";
   }
   $gd_scan_line = substr($gd_scan_line, 0, $width);
  }
  else if($bits == 1) {
   $gd_scan_line = "";
   $j = 0;
   while($j < $scan_line_size) {
    $byte = ord($scan_line{$j++});
    $p1 = chr((int) (($byte & 0x80) != 0));
    $p2 = chr((int) (($byte & 0x40) != 0));
    $p3 = chr((int) (($byte & 0x20) != 0));
    $p4 = chr((int) (($byte & 0x10) != 0));
    $p5 = chr((int) (($byte & 0x08) != 0));
    $p6 = chr((int) (($byte & 0x04) != 0));
    $p7 = chr((int) (($byte & 0x02) != 0));
    $p8 = chr((int) (($byte & 0x01) != 0));
    $gd_scan_line .= "$p1$p2$p3$p4$p5$p6$p7$p8";
   }
   $gd_scan_line = substr($gd_scan_line, 0, $width);
  }
  fwrite($dest_f, $gd_scan_line);
 }
 fclose($src_f);
 fclose($dest_f);
 return true;
}
function imagecreatefrombmp($filename) {
 $tmp_name = tempnam("tmp", "GD");
 if(ConvertBMP2GD($filename, $tmp_name)) {
  $img = imagecreatefromgd($tmp_name);
  unlink($tmp_name);
  return $img;
 }
 return false;
}
function mylog($msg)   // 偶加的
{
 $fp = fopen("mylog.txt", "a+");
 echo $msg."\n";
 fwrite($fp, $msg."\n");
 fclose($fp);
}
$img = imagecreatefrombmp("test24bit.bmp");
if($img)
{
 imagepng($img, "./test.png");  //原文是转成jpeg
}
?>
January 16

[原创] Linux 下 df 与 du的矛盾

今天遇到个奇怪的问题
[prcti01:root/1053]#du -h --max-depth=0
du: `./proc/10290/task': No such file or directory
du: `./proc/10290/fd': No such file or directory
du: `./proc/10291/task': No such file or directory
du: `./proc/10291/fd': No such file or directory
du: `./proc/10292/task': No such file or directory
du: `./proc/10292/fd': No such file or directory
du: `./proc/10293/task': No such file or directory
du: `./proc/10293/fd': No such file or directory
du: `./proc/10294/task': No such file or directory
du: `./proc/10294/fd': No such file or directory
du: `./proc/10295/task': No such file or directory
du: `./proc/10295/fd': No such file or directory
13G     .
[prcti01:root/1054]#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             142G  124G   11G  93% /
/dev/sda1              99M   13M   81M  14% /boot
none                  249M     0  249M   0% /dev/shm
 
以上可以看到du统计出来文件只占了13G, 但是df却统计出磁盘使用了124G,
怀疑有坏块或文件节点损坏也有用fsck -y修复了一下之后df的统计结果恢复正常了.
 
由此猜想du是按文件进行统计的, df是按磁盘节点进行统计的(包含坏的节点), 因此才会出现一开始统计信息矛盾的现象
 
January 14

[原创]一行SHELL搞定WEB访问量统计

目的:计算apache访问日志里,同一天每个IP的访问次数
相关命令: cat 、grep、sed、sort、uniq
运行系统: CentOS 4.4 我想linux系列都应该可以,但是freebsd和unix下需要对个别命令的option做一下修改
例子:
以下命令为统计2008年度的访问情况:
cat  access_log  | grep "/2008:" |sed -ur 's/([\S]*) .*\[(.*\/.*)\/.*:*\].*/\1:\2/' | sort -t: -k1 | uniq -c | sort -t: -k2
访问次数 IP:日期
         1 208.80.193.32:11/Jan
         1 211.1.219.173:11/Jan
    1324 202.94.148.161:11/Jan
     134 210.83.201.17:11/Jan
        2 116.80.158.100:11/Jan
      54 210.83.214.164:11/Jan
      55 210.83.223.115:11/Jan
     634 210.83.214.163:11/Jan
祝各位使用愉快
November 06

交叉线与平行线

是交叉线幸福一些还是相邻的平行线幸福一些呢?
September 25

无聊的中秋

今天中秋节,提前两个半小时就下班了挺高兴的,回到家里和儿子疯了一会儿,然后吃饭,这时才不到七点,往常这个时候也就是刚到家的样子,于是想偷懒玩会游戏,结果也被老婆和儿子破坏掉了,看孩子其实有的时候是挺烦的一件事情,不过既然身为人父有时候还是要尽一下义务的。
八点多外面的月亮升起来了,每家每户都在一起看电视聊天,楼上的小孩儿也兴奋的跑来跑去踩的楼板“通通”直响,虽说有点扰民但是节日里高兴也难怪嘛。让我很郁闷的是老婆儿子岳父岳母此时都已经睡觉了,才八点啊居然睡觉了,我在床上硬躺了半天,瞪着窗外的月亮心里有些难受,所以悄悄爬起来打开电脑排解一下心里的烦闷。
记得以前过节的时候和老婆总是相对聊天到很晚,那种感觉很温馨很安静,可是这种感觉已经很久没有体会过了,结婚之后尤其是有了孩子之后,夫妻间一起谈心的时候变的很少,有几次深夜中的对话也是在讨论你家怎么样我们怎么样或是别的一些并不让人感到愉快的乱七八糟的事情,难到婚姻真的是爱情的坟墓,MD这种感觉怎么那么让人觉得心烦。
明天是结婚纪念日我已经没有什么心情去庆祝了,该死的生活该死的TMD 烦透了,以后TMD天天加班,我看在公司的感觉也比在家里好
September 20

感冒了,好难过

天气忽冷忽热,一不小心感冒了,不断的打喷涕,流鼻涕,难过的要命
我挺~~~~
July 02

爱情转移

最近在学这首歌,  追忆一下逝去的日子.......



徘徊过多少橱窗住过多少旅馆 
才会觉得分离也并不冤枉 
感情是用来浏览还是用来珍藏 
好让日子天天都过得难忘 
熬过了多久患难湿了多少眼眶 
才能知道伤感是爱的遗产 
流浪几张双人床换过几次信仰 
才让戒指义无返顾的交换 
把一个人的温暖转移到另一个的胸膛 
让上次犯的错反省出梦想 
每个人都是这样享受过提心吊胆 
才拒绝做爱情待罪的羔羊 
会议是捉不到的月光握紧就变黑暗 
等虚假的背影消失于晴朗 
阳光在身上流转等所有业障被原谅 
爱情不停站想开往地老天荒 
需要多勇敢 
烛光照亮了晚餐照不出个答案 
恋爱不是温馨的请客吃饭 
床单上铺满花瓣拥抱让它成长 
太拥挤就开到了别的土壤 
感情需要人接班接近换来期望 
期望带来失望的恶性循环 
短暂的总是浪漫漫长总会不满 
烧完美好青春换一个老伴 
你不要失望荡气回肠是为了 
最美的平凡
May 17

很累很累

本来不想写什么的,最近实在是累的要命,连续一个多月的加班,今天更是一直到早上六点才睡,九点又要爬起来去公司。脑子里一天都晕乎乎的,刚看了蜡笔老刘的日志,深有感触,觉得应该写点什么记下此时的心情。
 
与他接触时间不长,但却让我深感佩服,无论是技术还是理论以及知识面,老刘都让我感到望尘莫及,这样的一个人不但没有丝毫的傲气,甚至连一点儿让你觉得不舒服的感觉都没有,完全就象是邻居家的大哥,人一辈子能遇到几个这样的人就会觉得人生其实很不错。
 
老刘的日志里写到“是男人就要挺住!”这句话让我觉的心里一酸,这个社会赋予男人太多的责任和义务了,有时候甚至让人有种无力为继的感觉,女人累了尚且可以找个男人依靠,但是男人累了除了“挺住”还能做什么呢。我们有太多的无奈太多的不满太多的委屈,可我们无人倾述或是说不能倾述,我们只能紧咬着牙关告诉自己“站直了,别趴下!”。
 
像老刘这种男人轻易不会喊累的,如果哪一天说“有点累了!”,那么其间的辛苦就远非一般人可以承受的住的了。
 
唉~祝老刘身体健康万事顺意吧。
 
April 23

杀进股市,合伙捞钱~~

股市牛气冲天,偶也赶把潮流,到股海沉浮一回
 
上周五7块7毛4买进的重庆钢铁200股 今天收盘是8块1毛3赚了77块4毛6, 长得有点慢,而且风险有些大了,想在8块3左右卖掉它。
早上9块5毛8买进300股金马股份  收盘时是10块4毛3,涨停, 赚了253块4毛钱 (我看好你哦,明天给我继续涨停)
 
600260 600340 600475看指标样子不错,吃进的话,估计还能小赚一笔,
 
股市全面泛红,估计今年会有个好收成。
April 16

[原创]YUM手工安装-适用于Centos,Redhat,Fedora,RHEL

YUM是个不错的包管理器,以后不用辛苦的一个个rpm了
以下是偶安装配置的过程,弟兄们酌情参考修改:
OS: Red Hat Enterprise Linux WS release 4
安装yum:
   下载: wget http://linux.duke.edu/projects/yum/download/2.0/yum-2.0.7-1.noarch.rpm
   安装: rpm -i yum-2.0.7-1.noarch.rpm
修改/etc/yum.conf
/etc/yum.conf内容
 [main]
 cachedir=/var/cache/yum
 debuglevel=2
 logfile=/var/log/yum.log
 pkgpolicy=newest
 distroverpkg=centos-release
 tolerant=1
 exactarch=1
 retries=20
 obsoletes=1
 gpgcheck=1
 [base]
 name=CentOS-4 - Base
 baseurl=http://mirror.centos.org/centos/4/os/i386/ 目录自己到上面去看一下,哪个版本适合自己
 gpgcheck=1
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
 #released updates
 [update]
 name=CentOS-4 - Updates
 baseurl=http://mirror.centos.org/centos/4/updates/i386/
 gpgcheck=1
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
 #packages used/produced in the build but not released
 [addons]
 name=CentOS-4 - Addons
 baseurl=http://mirror.centos.org/centos/4/addons/i386/
 gpgcheck=1
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
 #additional packages that may be useful
 [extras]
 name=CentOS-4 - Extras
 baseurl=http://mirror.centos.org/centos/4/extras/i386/
 gpgcheck=1
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
 #additional packages that extend functionality of existing packages
 [centosplus]
 name=CentOS-4 - Plus
 baseurl=http://mirror.centos.org/centos/4/centosplus/i386/
 gpgcheck=1
 enabled=0
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
 #contrib - packages by Centos Users
 [contrib]
 name=CentOS-4 - Contrib
 baseurl=http://mirror.centos.org/centos/4/contrib/i386/
 gpgcheck=1
 enabled=0
 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
导入公钥:
    rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
使用实例
1、搜索一个包
[root@localhost etc]# yum search subversion
 (略)
 Finding updated packages
 Downloading needed headers
 Looking in available packages for a providing package
 Available package: subversion-devel.i386 0:1.1.4-2.ent from base matches with
  Development package for Subversion developers.
 Available package: subversion-devel.i386 0:1.1.4-2.ent from base matches with
  subversion-devel
 Available package: subversion-perl.i386 0:1.1.4-2.ent from base matches with
  This package includes the Perl bindings to the Subversion libraries.
 Available package: subversion-perl.i386 0:1.1.4-2.ent from base matches with
  Perl bindings to the Subversion libraries
 Available package: subversion-perl.i386 0:1.1.4-2.ent from base matches with
  subversion-perl
 Available package: mod_dav_svn.i386 0:1.1.4-2.ent from base matches with
  Apache server module for Subversion server.
 6 results returned
 Looking in installed packages for a providing package
 Installed package: subversion.i386 0:1.1.4-2.ent matches with  -->我已经安过了所以出现在这里,呵呵
  subversion
 1 results returned
2、安装一个包
[root@localhost etc]# yum search subversion-perl.i386 0:1.1.4-2.ent
PS:
[root@asterisk1 etc]# yum -h
usage: yum [options] < update | install | info | remove | list |
    clean | provides | search | check-update | groupinstall |
    groupupdate | grouplist | groupinfo | groupremove |
    makecache | localinstall | erase | upgrade | whatprovides |
    localupdate | resolvedep | shell | deplist >
options:
  -h, --help            show this help message and exit
  -t, --tolerant        be tolerant of errors
  -C                    run entirely from cache, don't update cache
  -c [config file]      config file location
  -R [minutes]          maximum command wait time
  -d [debug level]      debugging output level
  -e [error level]      error output level
  -y                    answer yes for all questions
  --version             show Yum version and exit
  --installroot=[path]  set install root
  --enablerepo=[repo]   enable one or more repositories (wildcards allowed)
  --disablerepo=[repo]  disable one or more repositories (wildcards allowed)
  --exclude=[package]   exclude package(s) by name or glob
  --obsoletes           enable obsoletes processing during updates
  --noplugins           disable Yum plugins
View more entries