PHP does not use the GD library to generate the current time PNG format image of the program 1th/2 page _php tips

Source: Internet
Author: User
Tags chr strlen
<?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);
}
Functions for generating digital images
function Draw2digits ($x, $y, $number)
{
Draw_digit ($x, $y, (int) ($number/10));
Draw_digit ($x + one, $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;
$x 0 = $lines [$j] * $m + $x;
$y 0 = $lines [$j + 1] * $m + $y;
$x 1 = $lines [$j + 2] * $m + $x;
$y 1 = $lines [$j + 3] * $m + $y;
if ($x 0 = $x 1) {
$ofs = 3 * ($SX * $y 0 + $x 0);
for ($h = $y 0; $h <= $y 1; $h + +, $ofs + + 3 * $sx) {
$pixels [$ofs] = chr (0);
$pixels [$ofs + 1] = chr (0);
$pixels [$ofs + 2] = chr (0);
}
} else {
$ofs = 3 * ($SX * $y 0 + $x 0);
for ($w = $x 0; $w <= $x 1; $w + +) {
$pixels [$ofs + +] = chr (0);
$pixels [$ofs + +] = chr (0);
$pixels [$ofs + +] = chr (0);
}
}
}
}
}

Add text to the image
function Add_chunk ($type)
{
Global $result, $data, $chunk, $CRC _table;

Chunk: For layers
Length:4 bytes: Used to compute chunk
Chunk Type:4 bytes
Chunk Data:length bytes
Crc:4 bytes: Cyclic Redundancy code checksum

Copy data and create CRC checksum
$len = strlen ($data);
$chunk = Pack ("c*", ($len >>) & 255,
($len >>) & 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 + +) {
$c 8 = ($c >> 8) & 0xFFFFFF;
$c = $CRC _table[($c ^ ord ($chunk [$n])) & 0xFF] ^ $c 8;
}
$CRC = $c ^ $z;

$chunk. = Chr (($CRC >>) & 255);
$chunk. = Chr (($CRC >>) & 255);
$chunk. = Chr (($CRC >> 8) & 255);
$chunk. = Chr ($CRC & 255);

Add the results to the $result
$result. = $chunk;
}


Main program

$SX = 80;
$sy = 21;
$pixels = "";

Fill
for ($h = 0; $h < $sy; $h + +) {
for ($w = 0; $w < $sx; $w + +) {
$r = 100/$SX * $w + 155;
$g = 100/$sy * $h + 155;
$b = 255-($SX + $sy) * ($w + $h));
$pixels. = Chr ($r);
$pixels. = Chr ($g);
$pixels. = Chr ($b);
}
}
current 1/2 page   1 2 Next read the full text
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.