php不用GD庫(kù)生成當(dāng)前時(shí)間的PNG格式圖象的程序第1/2頁(yè)
更新時(shí)間:2008年09月28日 14:40:24 作者:
該程序是不用GD庫(kù)可以生成當(dāng)前時(shí)間的PNG格式圖象,給人大開(kāi)眼界,很有參考價(jià)值. teaman整理
<?php
function set_4pixel($r, $g, $b, $x, $y)
{
global $sx, $sy, $pixels;
$ofs = 3 * ($sx * $y + $x);
$pixels[$ofs] = chr($r);
$pixels[$ofs + 1] = chr($g);
$pixels[$ofs + 2] = chr($b);
$pixels[$ofs + 3] = chr($r);
$pixels[$ofs + 4] = chr($g);
$pixels[$ofs + 5] = chr($b);
$ofs += 3 * $sx;
$pixels[$ofs] = chr($r);
$pixels[$ofs + 1] = chr($g);
$pixels[$ofs + 2] = chr($b);
$pixels[$ofs + 3] = chr($r);
$pixels[$ofs + 4] = chr($g);
$pixels[$ofs + 5] = chr($b);
}
//生成數(shù)字圖象的函數(shù)
function draw2digits($x, $y, $number)
{
draw_digit($x, $y, (int) ($number / 10));
draw_digit($x + 11, $y, $number % 10);
}
function draw_digit($x, $y, $digit)
{
global $sx, $sy, $pixels, $digits, $lines;
$digit = $digits[$digit];
$m = 8;
for ($b = 1, $i = 0; $i < 7; $i++, $b *= 2) {
if (($b & $digit) == $b) {
$j = $i * 4;
$x0 = $lines[$j] * $m + $x;
$y0 = $lines[$j + 1] * $m + $y;
$x1 = $lines[$j + 2] * $m + $x;
$y1 = $lines[$j + 3] * $m + $y;
if ($x0 == $x1) {
$ofs = 3 * ($sx * $y0 + $x0);
for ($h = $y0; $h <= $y1; $h++, $ofs += 3 * $sx) {
$pixels[$ofs] = chr(0);
$pixels[$ofs + 1] = chr(0);
$pixels[$ofs + 2] = chr(0);
}
} else {
$ofs = 3 * ($sx * $y0 + $x0);
for ($w = $x0; $w <= $x1; $w++) {
$pixels[$ofs++] = chr(0);
$pixels[$ofs++] = chr(0);
$pixels[$ofs++] = chr(0);
}
}
}
}
}
//將文字加入到圖象中
function add_chunk($type)
{
global $result, $data, $chunk, $crc_table;
// chunk :為層
// length: 4 字節(jié): 用來(lái)計(jì)算 chunk
// chunk type: 4 字節(jié)
// chunk data: length bytes
// CRC: 4 字節(jié): 循環(huán)冗余碼校驗(yàn)
// copy data and create CRC checksum
$len = strlen($data);
$chunk = pack("c*", ($len >> 24) & 255,
($len >> 16) & 255,
($len >> 8) & 255,
$len & 255);
$chunk .= $type;
$chunk .= $data;
// calculate a CRC checksum with the bytes chunk[4..len-1]
$z = 16777215;
$z |= 255 << 24;
$c = $z;
for ($n = 4; $n < strlen($chunk); $n++) {
$c8 = ($c >> 8) & 0xffffff;
$c = $crc_table[($c ^ ord($chunk][$n])) & 0xff] ^ $c8;
}
$crc = $c ^ $z;
$chunk .= chr(($crc >> 24) & 255);
$chunk .= chr(($crc >> 16) & 255);
$chunk .= chr(($crc >> 8) & 255);
$chunk .= chr($crc & 255);
// 將結(jié)果加到$result中
$result .= $chunk;
}
//主程序
$sx = 80;
$sy = 21;
$pixels = "";
// 填充
for ($h = 0; $h < $sy; $h++) {
for ($w = 0; $w < $sx; $w++) {
$r = 100 / $sx * $w + 155;
$g = 100 / $sy * $h + 155;
$b = 255 - (100 / ($sx + $sy) * ($w + $h));
$pixels .= chr($r);
$pixels .= chr($g);
$pixels .= chr($b);
}
}
function set_4pixel($r, $g, $b, $x, $y)
{
global $sx, $sy, $pixels;
$ofs = 3 * ($sx * $y + $x);
$pixels[$ofs] = chr($r);
$pixels[$ofs + 1] = chr($g);
$pixels[$ofs + 2] = chr($b);
$pixels[$ofs + 3] = chr($r);
$pixels[$ofs + 4] = chr($g);
$pixels[$ofs + 5] = chr($b);
$ofs += 3 * $sx;
$pixels[$ofs] = chr($r);
$pixels[$ofs + 1] = chr($g);
$pixels[$ofs + 2] = chr($b);
$pixels[$ofs + 3] = chr($r);
$pixels[$ofs + 4] = chr($g);
$pixels[$ofs + 5] = chr($b);
}
//生成數(shù)字圖象的函數(shù)
function draw2digits($x, $y, $number)
{
draw_digit($x, $y, (int) ($number / 10));
draw_digit($x + 11, $y, $number % 10);
}
function draw_digit($x, $y, $digit)
{
global $sx, $sy, $pixels, $digits, $lines;
$digit = $digits[$digit];
$m = 8;
for ($b = 1, $i = 0; $i < 7; $i++, $b *= 2) {
if (($b & $digit) == $b) {
$j = $i * 4;
$x0 = $lines[$j] * $m + $x;
$y0 = $lines[$j + 1] * $m + $y;
$x1 = $lines[$j + 2] * $m + $x;
$y1 = $lines[$j + 3] * $m + $y;
if ($x0 == $x1) {
$ofs = 3 * ($sx * $y0 + $x0);
for ($h = $y0; $h <= $y1; $h++, $ofs += 3 * $sx) {
$pixels[$ofs] = chr(0);
$pixels[$ofs + 1] = chr(0);
$pixels[$ofs + 2] = chr(0);
}
} else {
$ofs = 3 * ($sx * $y0 + $x0);
for ($w = $x0; $w <= $x1; $w++) {
$pixels[$ofs++] = chr(0);
$pixels[$ofs++] = chr(0);
$pixels[$ofs++] = chr(0);
}
}
}
}
}
//將文字加入到圖象中
function add_chunk($type)
{
global $result, $data, $chunk, $crc_table;
// chunk :為層
// length: 4 字節(jié): 用來(lái)計(jì)算 chunk
// chunk type: 4 字節(jié)
// chunk data: length bytes
// CRC: 4 字節(jié): 循環(huán)冗余碼校驗(yàn)
// copy data and create CRC checksum
$len = strlen($data);
$chunk = pack("c*", ($len >> 24) & 255,
($len >> 16) & 255,
($len >> 8) & 255,
$len & 255);
$chunk .= $type;
$chunk .= $data;
// calculate a CRC checksum with the bytes chunk[4..len-1]
$z = 16777215;
$z |= 255 << 24;
$c = $z;
for ($n = 4; $n < strlen($chunk); $n++) {
$c8 = ($c >> 8) & 0xffffff;
$c = $crc_table[($c ^ ord($chunk][$n])) & 0xff] ^ $c8;
}
$crc = $c ^ $z;
$chunk .= chr(($crc >> 24) & 255);
$chunk .= chr(($crc >> 16) & 255);
$chunk .= chr(($crc >> 8) & 255);
$chunk .= chr($crc & 255);
// 將結(jié)果加到$result中
$result .= $chunk;
}
//主程序
$sx = 80;
$sy = 21;
$pixels = "";
// 填充
for ($h = 0; $h < $sy; $h++) {
for ($w = 0; $w < $sx; $w++) {
$r = 100 / $sx * $w + 155;
$g = 100 / $sy * $h + 155;
$b = 255 - (100 / ($sx + $sy) * ($w + $h));
$pixels .= chr($r);
$pixels .= chr($g);
$pixels .= chr($b);
}
}
相關(guān)文章
php實(shí)現(xiàn)對(duì)兩個(gè)數(shù)組進(jìn)行減法操作的方法
這篇文章主要介紹了php實(shí)現(xiàn)對(duì)兩個(gè)數(shù)組進(jìn)行減法操作的方法,涉及php操作數(shù)組的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04PHP實(shí)現(xiàn)多維數(shù)組多字段自定義排序
這篇文章主要介紹了PHP實(shí)現(xiàn)多維數(shù)組多字段自定義排序,通過(guò)將待排序數(shù)組的各個(gè)數(shù)組的$field保存在一維數(shù)組fieldArr中,在傳入array_multisort中參與排序,相當(dāng)于對(duì)$field一維數(shù)組的排序,而后根據(jù)排序后的key重新構(gòu)建傳入的待排序數(shù)組,需要的朋友可以參考下2023-10-10php彈出對(duì)話框?qū)崿F(xiàn)重定向代碼
本為大家介紹下使用php或js彈出對(duì)話框?qū)崿F(xiàn)重定向,具體示例如下,感興趣的朋友不要錯(cuò)過(guò)2014-01-01PHP讀取TXT文本內(nèi)容的五種實(shí)用方法小結(jié)
PHP作為一種流行的服務(wù)器端腳本語(yǔ)言,提供了多種方法來(lái)讀取TXT文本內(nèi)容,本文主要為大家詳細(xì)介紹五種不同的PHP方法,希望對(duì)大家有所幫助2024-01-01php和C#的yield迭代器實(shí)現(xiàn)方法對(duì)比分析
這篇文章主要介紹了php和C#的yield迭代器實(shí)現(xiàn)方法,簡(jiǎn)單說(shuō)明了yield迭代器的原理,并結(jié)合具體實(shí)例形式對(duì)比分析了php和C#的yield迭代器相關(guān)使用技巧,需要的朋友可以參考下2019-07-07PHP中單引號(hào)與雙引號(hào)的區(qū)別分析
在PHP中,我們可以使用單引號(hào)或者雙引號(hào)來(lái)表示字符串。不過(guò)我們作為開(kāi)發(fā)者,應(yīng)該了解其中的區(qū)別。單引號(hào)與雙引號(hào)對(duì)于定義字符一個(gè)是可以解析變量一個(gè)是會(huì)把變量直接輸出來(lái),同時(shí)單引號(hào)與雙引號(hào)在字符處理上單引號(hào)要優(yōu)與雙引號(hào)2014-08-08