本帖最后由 余超 于 2012-10-13 20:50 编辑
phpinfo函数中有趣的PHP Logo和Zend Logo图片(原创)
余超 yuchao86@gmail.com
打开PHP的源代码,当你试图找到logo.gif时,却找不到此文件,那phpinfo.php输出的PHPlogo是怎么生存的呢??
查看phpinfo.php文件中对应的源代码也只能看到这样一个链接phpinfo.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42,究竟是怎么生成的呢?
下面我们来看./main/logos.h 文件中,用zend_logo与php_logo数组保存了PHP标志和Zend标志。所以你根本在发行包里找不到zend.gif文件,
如下所示:
#define CONTEXT_TYPE_IMAGE_GIF "Content-Type: image/gif"
static const unsigned char zend_logo[] = {
71, 73, 70, 56, 57, 97, 113, 0, 72, 0,
213, 0, 0, 13, 13, 14, 1, 3, 6, 2,
//省略中间部分
46, 143, 167, 96, 131, 23, 221, 120, 200, 72,
214, 74, 16, 0, 0, 59 };
static const unsigned char php_logo[] = {
71, 73, 70, 56, 57, 97, 120, 0, 67, 0,
230, 106, 0, 127, 130, 184, 57, 55, 71, 40,
//省略中间部分
21, 116, 187, 251, 221, 240, 142, 119, 188, 3,
1, 0, 59, 0 };
static const unsigned char php_egg_logo[] = {
71, 73, 70, 56, 57, 97, 120, 0, 67, 0,
231, 255, 0, 18, 25, 33, 32, 30, 34, 28,
//省略中间部分,这个是愚人节发送的彩蛋logo
54, 240, 3, 66, 148, 6, 228, 178, 11, 192,
192, 4, 236, 158, 239, 2, 17, 16, 0, 59};
现在可能你又有疑问了??这些数字是怎么生成图片的呢?
请看下面一个程序:
<?php
$filename = "logo-small.gif";
$fp = fopen($filename, "rb");
$buffer = fread ($fp, filesize ($filename));
fclose($fp);
$len = strlen($buffer);
$fp = fopen("logo-small.h", "wb");
fwrite($fp, "unsigned char php_logo[] = {");
for ($i=0; $i<=$len; $i++) {
if($i % 10 == 0) {
fwrite($fp, "\n\t\t");
}
if($i == $len) {
$str = str_pad(ord(substr($buffer, $i, 1)), 3, " ", STR_PAD_LEFT);
} else {
$str = str_pad(ord(substr($buffer, $i, 1)), 3, " ", STR_PAD_LEFT) . ", ";
}
fwrite($fp, $str);
}
fwrite($fp, " };\n");
fclose($fp);
?>
这个是上一个过程的逆过程,就是把一张gif图片转换成一个C语言的数组并存放到.h头文件中,
转换后同样可以得到一个相应的数组如下:
unsigned char php_logo[] = {
71, 73, 70, 56, 55, 97, 51, 0, 51, 0,
244, 0, 0, 251, 121, 34, 251, 129, 48, 252,
138, 62, 252, 146, 76, 252, 155, 89, 252, 163,
103, 253, 171, 117, 253, 180, 131, 253, 188, 145,
253, 197, 159, 254, 205, 173, 254, 213, 187, 254,
222, 200, 254, 230, 214, 255, 239, 228, 255, 247,
242, 255, 255, 255, 0, 0, 0, 0, 0, 0,
...................... };
用这个数组替换掉./main/logos.h中相应的数组内容就可以更换logo了,
ord函数是转换为对应的ASCII码,而str_pad函数则是使用数组对齐,STR_PAD_LEFT参数是左对齐
最后重新编译一下PHP源代码即可修改phpinfo中的LOGO及ZENDLOGO了。 另外你可以使用php_logo_guid()和zend_logo_guid()函数如下语句生成PHPlogo和ZENDlogo
echo '<img src="' . $_SERVER['PHP_SELF'] .
'?=' . php_logo_guid() . '" alt="PHP Logo !" />';
通过我执行发现,这个guid值始终是一个,在编译的时候就确定的了。 参考: http://bytes.com/topic/php/answers/561086-phpinfo-how-does-generates-php-logo
http://hk2.php.net/php_logo_guid
http://hk2.php.net/zend_logo_guid
|