Paste a section of PHP drawing program, to hope to use PHP drawing friends a little inspiration, help!

Source: Internet
Author: User
Tags date array count key ord strlen trim utf 8
The procedure consists mainly of three documents:
1, view.php is the calling procedure.
2, chart.php is used to generate the chart of the program.
3, gbtoutf8.php is used in Chinese decoding (note: has been resolved in both English and Chinese can not properly display the problem)

1, view.php
?
Include ("gbtoutf8.php");
?>
<title> </title>
<meta name= "Author" content= "XIANG Li" >
?
* * Here data can be obtained from the database.
$ASTR = "It,pc,phone,sever,passport,software";
$aSoft = "Win2000,win98,office,foxmail,outlook";
$aHard = Gb2utf8 ("Floors, windows, glass, tables, tubes, vegetation");
$title 1 = Gb2utf8 (' 2002 It Maintenance ");
$title 2 = Gb2utf8 (' 2002 software Maintenance ");
$title 3 = Gb2utf8 (' 2002 fixed Assets ');
?>
<body>
<div align= "center" >
<table>
<tr>
<td><input type= "image" src= "/chart.php?astr=<?= $aStr >&title=<?= $title 1?>" ></td >
</tr>
<tr><td> </td></tr>
<tr>
<td><input type= "image" src= "/chart.php?astr=<?= $aSoft >&title=<?= $title 2?>" ></ Td>
</tr>
<tr><td> </td></tr>
<tr>
<td><input type= "image" src= "/chart.php?astr=<?= $aHard >&title=<?= $title 3?>" ></ Td>
</tr>
</table></div>
</body>

2, chart.php
<?php
/*
* Function: Generate statistics chart
* Programmer: WLXZ
* Date: 2002-00-00
*/

Header ("Content-type:image/png");
$im = Imagecreate (350, 280);
$col _oth = imagecolorallocate ($im, 0,0,0);
$col _orn = imagecolorallocate ($im, 255,192,0);
$col _yel = imagecolorallocate ($im, 255,255,0);
$col _red = imagecolorallocate ($im, 255,0,0);
$col _grn = imagecolorallocate ($im, 0,255,0);
$col _blu = imagecolorallocate ($im, 0,0,255);
$col _wit = imagecolorallocate ($im, 255,255,255);
$col _array = Array ($col _oth, $col _orn, $col _yel, $col _red, $col _grn, $col _blu);

$dot 1 = 28;
$dot 2 = 20;
$font = "C:/winnt/fonts/simhei.ttf";
$ASTR = Explode (",", Trim ($_get[' aStr '));
$title = Trim ($_get[' title ')];

Imagettftext ($im, 18,0,100,50, $col _wit, $font, $title);//write title

For ($i =1 $i <count ($col _array); $i + +) {
Imagefilledrectangle ($im, 50* $i-$dot 2, $dot 1* $i, 50* $i, $col _array[$i]);
Imagerectangle ($im, 50* $i-$dot 2, $dot 1* $i, 50* $i, $col _wit);
Imagerectangle ($im, 50* $i-$dot 2-1, $dot 1* $i -1,50* $i +1,200, $col _wit);
Imagettftext ($im, 14,270,50* $i -15,205, $col _wit, $font, $aStr [$i-1]);

Imageline ($im, 50* $i-$dot 2, $dot 1* $i, 50* $i-$dot 2,200, $col _wit);
Imageline ($im, 50* $i-$dot 2, $dot 1* $i, 50* $i, $dot 1* $i, $col _wit);
}
Imagerectangle ($im, 10,10,300,200, $col _wit);
Imagerectangle ($im, 11,11,301,201, $col _wit);

Percent to right
For ($i =1 $i <count ($col _array); $i + +) {
Imageline ($im, $i *33,306, $i *33, $col _wit);
$str = (100-$i *5). " %";
Imagettftext ($im, 14,0,315, $i *33+2, $col _wit, $font, $STR);
}

Imagepng ($im);
Imagedestroy ($im);
?>

3.gbtoutf8.php
?
/*
* Function: Converts GB2312 code into UTF-8 encoding
* Programmer: WLXZ
* Date: 2002-00-00
*/

function Gb2utf8 ($GB) {
if (!trim ($GB))
return $GB;

$filename = "Gb2312.txt";
$tmp =file ($filename);
$codetable =array ();

while (list ($key, $value) =each ($tmp))
$codetable [Hexdec (substr ($value, 0,6))]=substr ($value, 7,6);

$ret = "";
$utf 8 = "";

while ($GB) {
if (Ord (substr ($GB, 0,1)) >127)
{
$this =substr ($GB, 0,2);
$GB =substr ($GB, 2,strlen ($GB));
$utf 8=u2utf8 (Hexdec ($codetable [Hexdec (Bin2Hex ($this)) -0x8080]);

for ($i =0; $i <strlen ($utf 8); $i +=3)
$ret. =CHR (substr ($utf 8, $i, 3));
}
else{
$ret. =substr ($GB, 0, 1);
$GB =substr ($GB, 1,strlen ($GB));
}
}

return $ret;
}

function U2utf8 ($c) {
for ($i =0; $i <count ($c); $i + +)
$str = "";

if ($c < 0x80) {
$str. = $c;
}
else if ($c < 0x800) {
$str. = (0xc0 | $c >>6);
$str. = (0x80 | $c & 0x3F);
}
else if ($c < 0x10000) {
$str. = (0xe0 | $c >>12);
$str. = (0x80 | $c >>6 & 0x3F);
$str. = (0x80 | $c & 0x3F);
}
else if ($c < 0x200000) {
$str. = (0xF0 | $c >>18);
$str. = (0x80 | $c >>12 & 0x3F);
$str. = (0x80 | $c >>6 & 0x3F);
$str. = (0x80 | $c & 0x3F);
}

return $str;
}


function Gb2unicode ($GB) {
if (!trim ($GB))
return $GB;

$filename = "Gb2312.txt";
$tmp =file ($filename);
$codetable =array ();

while (list ($key, $value) =each ($tmp))
$codetable [Hexdec (substr ($value, 0,6))]=substr ($value, 9,4);
$utf = "";
while ($GB) {
if (Ord (substr ($GB, 0,1)) >127) {
$this =substr ($GB, 0,2);
$GB =substr ($GB, 2,strlen ($GB));
$utf. = "& #x". $codetable [Hexdec (Bin2Hex ($this)) -0x8080]. ";";
}
else{
$GB =substr ($GB, 1,strlen ($GB));
$utf. =substr ($GB, 0, 1);
}
}
return $UTF;
}
?>

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.