// compressed data blocks: n bytes
// one block (RFC-1951):
// bit 0: BFINAL: 1 for the last block
// bit 1 and 2: BTYPE: 0 for no compression
// next 2 bytes: LEN (LSB first)
// next 2 bytes: one's complement of LEN
// LEN bytes uncompressed data
// check value: 4 bytes (Adler-32 checksum of the uncompressed data)
//
$len = ($sx * 3 + 1) * $sy;
$data = pack("c*", 0x78, 0x01,
1,
$len & 255,
($len >> 8) & 255,
255 - ($len & 255),
255 - (($len >> 8) & 255));
$start = strlen($data);
$i2 = 0;
for ($h = 0; $h < $sy; $h++) {
$data .= chr(0);
for ($w = 0; $w < $sx * 3; $w++) {
$data .= $pixels[$i2++];
}
}
// calculate a Adler32 checksum with the bytes data[start..len-1]
$s1 = 1;
$s2 = 0;
for ($n = $start; $n < strlen($data); $n++) {
$s1 = ($s1 + ord($data[$n])) % 65521;
$s2 = ($s2 + $s1) % 65521;
}
$adler = ($s2 << 16) | $s1;
$data .= chr(($adler >> 24) & 255);
$data .= chr(($adler >> 16) & 255);
$data .= chr(($adler >> 8) & 255);
$data .= chr($adler & 255);
add_chunk("IDAT");
// IEND: marks the end of the PNG-file
$data = "";
add_chunk("IEND");
// 列印图象
echo($result);
?>
//如何调用,其实很简单,将上面存为Timeimg.php
//然后新建一个页面如下:
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html">
</head>
<body>
<img src="Timeimg.php"> //以图象连接方式调用PHP文件
</body>
</html>