ホームページ php教程 php手册 PHP 描画プログラムを投稿して、PHP を使って描画したい友達にインスピレーションを与えましょう。

PHP 描画プログラムを投稿して、PHP を使って描画したい友達にインスピレーションを与えましょう。

Jun 21, 2016 am 09:12 AM
gt lt nbsp quot

程序

主要包括三个文件:
1、view.php是调用程序。
2、chart.php是用来生成图表的程序。
3、gbtoutf8.php是用来中文解码的(注:已解决中英文混合不能正常显示的问题)

1、view.php
<?
include("gbtoutf8.php");
?>
<html>
<head>
<title>  </title>
<meta name="Author" content="XIANG Li">
</head>
<?
/*此处数据可从数据库中取得*/
$aStr = "IT,PC,Phone,Sever,Passport,Software";
$aSoft = "Win2000,Win98,Office,Foxmail,Outlook";
$aHard = gb2utf8("地板,窗户,玻璃,桌子,灯管,植被");
$title1 = gb2utf8('2002年IT维护report');
$title2 = gb2utf8('2002年软件维护report');
$title3 = gb2utf8('2002年固定资产report');
?>
<body>
<div align="center">
<table>
<tr>
    <td><input type="image" src="./chart.php?aStr=<?=$aStr?>&title=<?=$title1?>"></td>
</tr>
<tr><td> </td></tr>
<tr>
    <td><input type="image" src="./chart.php?aStr=<?=$aSoft?>&title=<?=$title2?>"></td>
</tr>
<tr><td> </td></tr>
<tr>
    <td><input type="image" src="./chart.php?aStr=<?=$aHard?>&title=<?=$title3?>"></td>
</tr>
</table></div>
</body>
</html>

2、chart.php
<?php
/*
* 機能:生成统计图表
* 程序员:wlxz
* 日期: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);

$dot1 = 28;
$dot2 = 20;
$font="c:/winnt/fonts/simhei.ttf";
$aStr =explode(",", trim($_GET[' aStr']));
$title =rim($_GET['title']);

ImageTTFText($im,18,0,100,50,$col_wit,$font,$title);//写标题

for($i=1;$i<count($col_array);$i++){
ImageFilledRectangle($im,50*$i-$dot2,$dot1*$i,50*$i,200,$col_array[ $i]);
ImageRectangle($im,50*$i-$dot2,$dot1*$i,50*$i,200,$col_wit);
ImageRectangle($im,50*$i-$dot2- 1,$dot1*$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-$dot2,$dot1*$i,50*$i-$dot2,200,$col_wit);
ImageLine($im,50*$i- $dot2,$dot1*$i,50*$i,$dot1*$i,$col_wit);
}
ImageRectangle($im,10,10,300,200,$col_wit);
ImageRectangle($im,11,11,301,201, $col_wit);

//右边百分比
for($i=1;$i<count($col_array);$i++){
ImageLine($im,300,$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
<?
/*
* 機能:取GB2312编码转换成UTF-8の编码
* 程序员:wlxz
* 日期:2002-00-00
*/

function 8 ($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 ="";
$utf8="";

while($gb){
if (ord(substr($gb,0,1))>127)
{
$this=substr($gb,0 ,2);
$gb=substr($gb,2,strlen($gb));
$utf8=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));

の場合($i=0;$i $ret.=chr(substr($utf8,$i,3));
}
else{
$ret.=部分文字列($gb,0,1);
$gb=substr($gb,1,strlen($gb));
}
}

return $ret;
}

function u2utf8($c){
向け($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 $str.=(0xE0 | $c>>12);
$str.=(0x80 | $c > ) $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.="".$codetable[hexdec(bin2hex($this ))-0x8080].";";
}
else{
$gb=substr($gb,1,strlen($gb));
$utf.=substr($gb,0 ,1);
}
}
return $utf;
}
?>



このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットな記事タグ

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

解決策: 組織では PIN を変更する必要があります。 解決策: 組織では PIN を変更する必要があります。 Oct 04, 2023 pm 05:45 PM

解決策: 組織では PIN を変更する必要があります。

Windows 11 でウィンドウの境界線の設定を調整する方法: 色とサイズを変更する Windows 11 でウィンドウの境界線の設定を調整する方法: 色とサイズを変更する Sep 22, 2023 am 11:37 AM

Windows 11 でウィンドウの境界線の設定を調整する方法: 色とサイズを変更する

Windows 11でタイトルバーの色を変更するにはどうすればよいですか? Windows 11でタイトルバーの色を変更するにはどうすればよいですか? Sep 14, 2023 pm 03:33 PM

Windows 11でタイトルバーの色を変更するにはどうすればよいですか?

Windows 11 でタスクバーのサムネイル プレビューを有効または無効にする方法 Windows 11 でタスクバーのサムネイル プレビューを有効または無効にする方法 Sep 15, 2023 pm 03:57 PM

Windows 11 でタスクバーのサムネイル プレビューを有効または無効にする方法

Windows 11/10修復におけるOOBELANGUAGEエラーの問題 Windows 11/10修復におけるOOBELANGUAGEエラーの問題 Jul 16, 2023 pm 03:29 PM

Windows 11/10修復におけるOOBELANGUAGEエラーの問題

Huawei GT3 ProとGT4の違いは何ですか? Huawei GT3 ProとGT4の違いは何ですか? Dec 29, 2023 pm 02:27 PM

Huawei GT3 ProとGT4の違いは何ですか?

Windows 11 でのディスプレイ スケーリング ガイド Windows 11 でのディスプレイ スケーリング ガイド Sep 19, 2023 pm 06:45 PM

Windows 11 でのディスプレイ スケーリング ガイド

Windows 11で明るさを調整する10の方法 Windows 11で明るさを調整する10の方法 Dec 18, 2023 pm 02:21 PM

Windows 11で明るさを調整する10の方法

See all articles