字符颜色等,//Y轴上刻度 $rulerY=$this-&gt

2020-01-01 23:46 来源:未知

<?php
  Class ImageReport{ 
var $X;//图片大小X轴 
var $Y;//图片大小Y轴 
var $R;//背影色R值 
var $G;//...G. 
var $B;//...B. 
var $TRANSPARENT;//是还是不是透明1或0 
var $IMAGE;//图片对像 
//------------------- 
var $ALacrosseRAYSPLIT;//钦定用于分隔数值的标识 
var $ITEMARRAY;//数值 
var $REPORTTYPE;//图表类型,1为竖柱形2为横柱形3为折线形 
var $BORDER;//距离 
//------------------- 
var $FONTSIZE;//字体大小 
var $FONTCOLOENVISION;//字体颜色 
//--------参数设置函数 
function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){ 
$this->X=$SizeX;  
$this->Y=$SizeY;  
$this->R=$R;  
$this->G=$G;  
$this->B=$B;  
$this->TRANSPARENT=$Transparent;  
}  
function setItem($ArraySplit,$ItemArray,$ReportType,$Border){  
$this->ARRAYSPLIT=$ArraySplit;  
$this->ITEMARRAY=$ItemArray;  
$this->REPORTTYPE=$ReportType;  
$this->BORDER=$Border;  
}  
function setFont($FontSize){  
$this->FONTSIZE=$FontSize;  
}  
//----------------主体  
function PrintReport(){  
Header( "Content-type: image/gif");  
//建立画布大小  
$this->IMAGE=ImageCreate($this->X,$this->Y);  
//设定画布背景象  
$background=ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B);  
if($this->TRANSPARENT=="1"){  
//背影透明  
Imagecolortransparent($this->IMAGE,$background);  
}else{  
//如不要透明时可填充背景观  
ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this->Y,$background);  
}  
//参数字体文小及颜色  
$this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);  
Switch ($this->REPORTTYPE){  
case "0":  
break;  
case "1":  
$this->imageColumnS();  
break;  
case "2":  
$this->imageColumnH();  
break;  
case "3":  
$this->imageLine();  
break;  
}  
$this->printXY();  
$this->printAll();  
}  
//-----------打印XY坐标轴  
function printXY(){  
//画XY坐标轴*/  
$color=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);  
$xx=$this->X/10;  
$yy=$this->Y-$this->Y/10;  
ImageLine($this->IMAGE,$this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER,$color);//X轴  
ImageLine($this->IMAGE,$this->BORDER,$this->Y-$this->BORDER,$this->X-$this->BORDER,$this->Y-$this->BORDER,$color);//y轴  
//Y轴上刻度  
$rulerY=$this->Y-$this->BORDER;  
while($rulerY>$this->BORDER*2){  
$rulerY=$rulerY-$this->BORDER;  
ImageLine($this->IMAGE,$this->BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);  
}  
//X轴上刻度  
$rulerX=$rulerX+$this->BORDER;  
while($rulerX<($this->X-$this->BORDER*2)){  
$rulerX=$rulerX+$this->BORDER;  
//ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER+10,10,$color);  
ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BORDER,$rulerX,$this->Y-$this->BORDER+2,$color);  
}  
}  

X=$SizeX; $this->Y=$SizeY; $this->Haval=$Sportage; $this->G=$G; $this->B=$B; $this->TRANSPARENT=$Transparent; } functionsetItem($ArraySplit,$ItemArray,$ReportType,$Border卡塔尔{ $this->A奥迪Q5RAYSPLIT=$ArraySplit; $this->ITEMA奇骏RAY=$ItemArray; $this->REPORTTYPE=$ReportType; $this->BORAV4DELacrosse=$Border; } functionsetFont{ $this->FONTSIZE=$FontSize; } //----------------主体 functionPrintReport(卡塔尔(قطر‎{ Header("Content-type:image/gif"卡塔尔; //创建画布大小 $this->IMAGE=ImageCreate; //设定画布背景象$background=ImageColorAllocate($this->IMAGE,$this->Tucson,$this->G,$this->B卡塔尔; if($this->TRANSPARENT=="1"State of Qatar{ //背影透明 Imagecolortransparent($this->IMAGE,$background卡塔尔(قطر‎; }else{ //如不要透明时可填充背景象ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this->Y,$background卡塔尔(قطر‎; } //参数字体文小及颜色 $this->FONTCOLOLX570=ImageColorAllocate($this->IMAGE,255-$this->君越,255-$this->G,255-$this->B卡塔尔; Switch{ case"0": break; case"1": $this->imageColumnS(卡塔尔; break; case"2": $this->imageColumnH(State of Qatar; break; case"3": $this->imageLine(卡塔尔; break; } $this->printXY; } //-----------打字与印刷XY坐标轴 functionprintXY(State of Qatar{ //画XY坐标轴*/ $color=ImageColorAllocate($this->IMAGE,255-$this->Tiggo,255-$this->G,255-$this->BState of Qatar; $xx=$this->X/10; $yy=$this->Y-$this->Y/10; ImageLine($this->IMAGE,$this->BOENCOREDERubicon,$this->BOTiguanDEENCORE,$this->BO巴博斯 SLK级DE翼虎,$this->Y-$this->BOTucsonDETiggo,$color卡塔尔;//X轴 ImageLine($this->IMAGE,$this->BO陆风X8DE昂科威,$this->Y-$this->BO本田UR-VDELX570,$this->X-$this->BO途达DEKoleos,$this->Y-$this->BORDE奥德赛,$color卡塔尔国;//y轴 //Y轴上刻度 $rulerY=$this->Y-$this->BO索罗德DEHighlander; while($rulerY>$this->BOTiguanDECRUISER*2卡塔尔国{ $rulerY=$rulerY-$this->BOPRADODE奥德赛; ImageLine($this->IMAGE,$this->BOEvoqueDE奥迪Q5,$rulerY,$this->BOWranglerDEPRADO-2,$rulerY,$color卡塔尔; } //X轴上刻度 $rulerX=$rulerX+$this->BO中华VDE帕杰罗; while($rulerXX-$this->BO牧马人DE翼虎*2卡塔尔(قطر‎卡塔尔{ $rulerX=$rulerX+$this->BOENCOREDE福特Explorer; //ImageLine($this->IMAGE,$this->BOSportageDE奇骏,10,$this->BOEnclaveDE本田CR-V+10,10,$colorState of Qatar; ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BO大切诺基DEHaval,$rulerX,$this->Y-$this->BOQX56DELX570+2,$color卡塔尔; } } //--------------竖柱形图 functionimageColumnS(卡塔尔(قطر‎{ $item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY); $num=Count; $item_max=0; for{ $item_max=Max($item_max,$item_array[$i]); } $xx=$this->BORDER*2; //画柱形图 for{ srand*1000000); if($this->R!=255&&$this->G!=255&&$this->B!=255卡塔尔{ $Sportage=Rand; $G=Rand; $B=Rand; }else{ $Murano=Rand; $G=Rand; $B=Rand; } $color=ImageColorAllocate($this->IMAGE,$奥迪Q5,$G,$BState of Qatar; //柱形中度$height=($this->Y-$this->BOWranglerDE揽胜极光卡塔尔-($this->Y-$this->BOEscortDETiggo*2)*($item_array[$i]/$item_max); ImageFilledRectangle($this->IMAGE,$xx,$height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color); ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLO昂科拉卡塔尔国; //用于间隔 $xx=$xx+$this->BO福睿斯DEENVISION*2; } } //-----------横柱形图 functionimageColumnH(卡塔尔(قطر‎{ $item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY); $num=Count; $item_max=0; for{ $item_max=Max($item_max,$item_array[$i]); } $yy=$this->Y-$this->BORDER*2; //画柱形图 for{ srand*1000000); if($this->R!=255&&$this->G!=255&&$this->B!=255State of Qatar{ $本田CR-V=Rand; $G=Rand; $B=Rand; }else{ $宝马X5=Rand; $G=Rand; $B=Rand; } $color=ImageColorAllocate($this->IMAGE,$路虎极光,$G,$BState of Qatar; //柱形长度 $leight=($this->X-$this->BO福特ExplorerDEENCORE*2)*($item_array[$i]/$item_max); ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color); ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLO中华V卡塔尔(قطر‎; //用于间隔 $yy=$yy-$this->BOQashqaiDE路虎极光*2; } } //--------------折线图 functionimageLine(){ $item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY); $num=Count; $item_max=0; for{ $item_max=Max($item_max,$item_array[$i]卡塔尔国; } //$xx=$this->BOWranglerDE奥迪Q3; //画柱形图 for{ srand*1000000); if($this->R!=255&&$this->G!=255&&$this->B!=255卡塔尔国{ $昂Cora=Rand; $G=Rand; $B=Rand; }else{ $奥迪Q5=Rand; $G=Rand; $B=Rand; } $color=ImageColorAllocate($this->IMAGE,$科雷傲,$G,$B卡塔尔国; //柱形中度$height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max); if{ ImageLine($this->IMAGE,$xx,$height_next,$xx+$this->BORDER,$height_now,$color); } ImageString($this->IMAGE,$this->FONTSIZE,$xx+$this->BORDER,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR); $height_next=$height_now; //用于间距 $xx=$xx+$this->BO奥迪Q5DESportage; } } //--------------完毕打字与印刷图形 functionprintAll(){ ImageGIF; ImageDestroy; } //--------------调试 functiondebug(){ echo"X:".$this->X." Y:".$this->Y; echo" BORDER:".$this->BORDER; $item_array=split($this->AWranglerRAYSPLIT,$this->ITEMAPAJERORAY卡塔尔(قطر‎; $num=Count; echo" 数值个数:".$num." 数值:"; for{ echo" ".$item_array[$i]; } } } $report=newImageReport; $report->setImage(600,300,255,255,255,1State of Qatar;//参数 $temparray="50,25,100,250,180,200,150,220,200,150,50,25,100,250,180,200,150,220,200,150";//数值,用钦定符号隔开$report->setItem;//参数(分隔数值的钦命符号,数值变量,样式1为竖柱图2为横柱图3为折线图,间隔)$report->setFont;//字体大小1-10 $report->PrintReport;//调式之用 ?>

完整实例

//--------------竖柱形图  
function imageColumnS(){  
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
$item_max=0;  
for ($i=0;$i<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

$xx=$this->BORDER*2;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}  
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//柱形中度  
$height=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);  
ImageFilledRectangle($this->IMAGE,$xx,$height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color);  
ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLOR);  
//用于间隔  
$xx=$xx+$this->BORDER*2;  
}  
}  

自动物检疫查评定背景和字体,并任意挑选背景图片中的一块范围,随机使用字体,展现验证字符串时随机突显字体大小,字符间距,字符颜色等

//-----------横柱形图  
function imageColumnH(){  
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
$item_max=0;  
for ($i=0;$i<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

$yy=$this->Y-$this->BORDER*2;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}  
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//柱形长度  
$leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);  
ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);  
ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);  
//用于间距  
$yy=$yy-$this->BORDER*2;  
}  
}  

 代码如下

//--------------折线图  
function imageLine(){  
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
$item_max=0;  
for ($i=0;$i<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

//$xx=$this->BORDER;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}  
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//柱形中度  
$height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);  
if($i!="0"){  
ImageLine($this->IMAGE,$xx,$height_next,$xx+$this->BORDER,$height_now,$color);  
}  
ImageString($this->IMAGE,$this->FONTSIZE,$xx+$this->BORDER,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR);  
$height_next=$height_now;  
//用于间隔  
$xx=$xx+$this->BORDER;  
}  
}  

<?php
/**
* Class for Validate image
* @author  zcs
* @version 1.0-20090828
*/

//--------------完结打字与印刷图形  
function printAll(){  
ImageGIF($this->IMAGE);  
ImageDestroy($this->IMAGE);  
}  
//--------------调试  
function debug(){  
echo "X:".$this->X."
Y:".$this->Y;  
echo "
BORDER:".$this->BORDER;  
$item_array=split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
echo "
数值个数:".$num."
数值:";  
for ($i=0;$i<$num;$i++){ 
echo "
".$item_array[$i];  
}  
}  
}  

session_start();
class validimg
{
//背景图片目录
var $backgroundpath = ‘validbg’;
//生成验证码宽度
var $width =’80′;
www.129028.com,//生成验证码中度
var $height =’25′;
//背景
var $background;
//验证文本
var $text=’abcd’;
//字体目录
var $fontpath = ‘validbg’;
//字体
var $font=’simhei.ttf’;
//字体宽度
var $font_width = ’20′;

$report=new ImageReport;  
$report->setImage(600,300,255,255,255,1卡塔尔国;//参数(长,宽,背影色君越,G,B,是不是透明1或0State of Qatar  
$temparray="50,25,100,250,180,200,150,220,200,150,50,25,100,250,180,200,150,220,200,150";//数值,用内定符号隔绝  
$report->setItem(',',$temparray,3,20卡塔尔国;//参数(分隔数值的钦定符号,数值变量,样式1为竖柱图2为横柱图3为折线图,间距State of Qatar  
$report->setFont(1卡塔尔;//字体大小1-10  
$report->PrintReport();  
//$report->debug(State of Qatar;//调式之用  
?>

function validimg($text)
{
$this->text = $text;
//随机选拔三个背景文件
$bgdir =  @dir($this->backgroundpath);
while(false !== ($image = $bgdir ->read()))
{
if($image != ‘.’ && $image != ‘..’ && $this->checktype($image) != false)
{
$backgroundarr[] = $image;

}
}
$bgdir->close();
//随机筛选一个字体文件
$fonts =  @dir($this->fontpath);
while(false !== ($font = $fonts ->read()))
{
if($font != ‘.’ && $font != ‘..’ && $this->checktype($font,’FONT’) != false)
{
$fontsarr[] = $font;
}
}
$fonts->close();
$this->font = $fontsarr[array_rand($fontsarr,1)];
$this->background = $backgroundarr[array_rand($backgroundarr,1)];

$this->output();
}

TAG标签:
版权声明:本文由www.129028.com-澳门金沙唯一官网www129028com发布于编程新闻,转载请注明出处:字符颜色等,//Y轴上刻度 $rulerY=$this-&gt