PHP No. 1/2 page of the Program for generating PNG images of the current time using the GD library

Source: Internet
Author: User

<? 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 );
}
// Function for generating digital images
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 );
}
}
}
}
}

// Add text to the image
Function add_chunk ($ type)
{
Global $ result, $ data, $ chunk, $ crc_table;

// Chunk: Layer
// Length: 4 Bytes: used to calculate chunk
// Chunk type: 4 bytes
// Chunk data: length bytes
// CRC: 4 Bytes: cyclic Verification

// 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) & 0 xffffff;
$ 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 );

// Add the result to $ result
$ Result. = $ chunk;
}

// MasterProgram

$ 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-(100/($ SX + $ SY) * ($ W + $ H);
$ pixels. = CHR ($ R);
$ pixels. = CHR ($ g);
$ pixels. = CHR ($ B);
}< BR >}

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.