php水印程序
<?php
require_once("../dbconnect.php");
$proimagepath="photo/";
$product_id=$_POST["product_id"];
$product_pid=$_POST["product_pid"];
$product_title=$_POST["product_title"];
$product_name=$_POST["product_name"];
$product_xinghao=$_POST["product_xinghao"];
$product_yongtu=$_POST["product_yongtu"];
$product_danjia=$_POST["product_danjia"];
$product_content=mysql_escape_string($_POST["content1"]);
$product_date=date("YmdHis");
$product_smallid=$_POST["product_catename"];
$product_img=$_FILES["smallimage"];
$smalltype=$product_img["type"];
////数据验证////////////////
if($product_name=="")
{
alert_back("产品名称不能为空!");
exit;
}
if(!$smalltype=getImgType($smalltype))
{
alert_back("上传的图片类型不对!");
exit;
}
///////////上传图片/////////////////
$smallimgname=$product_smallid.$product_date.".".$smalltype;
$smallimgpath=$proimagepath.$smallimgname;
if(!move_uploaded_file($product_img["tmp_name"],"../".$smallimgpath))
{
alert_back("上传图片失败!");
exit;
}
//////////添加数据到数据库///////////////
$insertSQL="insert into product (product_title,product_name,product_xinghao,product_yongtu,product_danjia,product_img,product_content,product_date,product_smallid,product_pid) values
('$product_title','$product_name','$product_xinghao','$product_yongtu','$product_danjia','$smallimgpath','$product_content','$product_date','$product_smallid','$product_pid')";
mysql_query("SET NAMES 'gb2312'");
//echo($insertSQL);
if(mysql_query($insertSQL))
{
alert_back("添加产品成功!");
}
else
{
alert_back("添加产品失败!");
}
?>
在网上找的水印代码:
/*
* 功能:PHP图片水印 (水印支持图片或文字)
* 参数:
* $product_img 背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterPos 水印位置,有10种状态,0为随机位置;
* 1为顶端居左,2为顶端居中,3为顶端居右;
* 4为中部居左,5为中部居中,6为中部居右;
* 7为底端居左,8为底端居中,9为底端居右;
* $waterImage 图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterText 文字水印,即把文字作为为水印,支持ASCII码,不支持中文;
* $textFont 文字大小,值为1、2、3、4或5,默认为5;
* $textColor 文字颜色,值为十六进制颜色值,默认为#FF0000(红色);
*
* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG
* $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。
* 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。
* 加水印后的图片的文件名和 $product_img 一样。
* 作者:longware @ 2004-11-3 14:15:13
*/
function imageWaterMark($product_img,$waterPos=0,$waterImage="",$waterText="",$textFont=5,$textColor="#FF0000")
{
$isWaterImage = FALSE;
$formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
//读取水印文件
if(!empty($waterImage) && file_exists($waterImage))
{
$isWaterImage = TRUE;
$water_info = getimagesize($waterImage);
$water_w = $water_info[0];//取得水印图片的宽
$water_h = $water_info[1];//取得水印图片的高
switch($water_info[2])//取得水印图片的格式
{
case 1water_im = imagecreatefromgif($waterImage);break;
case 2water_im = imagecreatefromjpeg($waterImage);break;
case 3water_im = imagecreatefrompng($waterImage);break;
default:die($formatMsg);
}
}
//读取背景图片
if(!empty($product_img) && file_exists($product_img))
{
$ground_info = getimagesize($product_img);
$ground_w = $ground_info[0];//取得背景图片的宽
$ground_h = $ground_info[1];//取得背景图片的高
switch($ground_info[2])//取得背景图片的格式
{
case 1:$ground_im = imagecreatefromgif($product_img);break;
case 2:$ground_im = imagecreatefromjpeg($product_img);break;
case 3:$ground_im = imagecreatefrompng($product_img);break;
default:die($formatMsg);
}
}
else
{
die("需要加水印的图片不存在!");
}
//水印位置
if($isWaterImage)//图片水印
{
$w = $water_w;
$h = $water_h;
$label = "图片的";
}
else//文字水印
{
$temp = imagettfbbox(ceil($textFont*2.5),0,"arial.ttf",$waterText);//取得使用 TrueType 字体的文本的范围
$w = $temp[2] - $temp[6];
$h = $temp[3] - $temp[7];
unset($temp);
$label = "文字区域";
}
if( ($ground_w<$w) || ($ground_h<$h) )
{
echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";
return;
}
switch($waterPos)
{
case 0://随机
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
case 1://1为顶端居左
$posX = 0;
$posY = 0;
break;
case 2://2为顶端居中
$posX = ($ground_w - $w) / 2;
$posY = 0;
break;
case 3://3为顶端居右
$posX = $ground_w - $w;
$posY = 0;
break;
case 4://4为中部居左
$posX = 0;
$posY = ($ground_h - $h) / 2;
break;
case 5://5为中部居中
$posX = ($ground_w - $w) / 2;
$posY = ($ground_h - $h) / 2;
break;
case 6://6为中部居右
$posX = $ground_w - $w;
$posY = ($ground_h - $h) / 2;
break;
case 7://7为底端居左
$posX = 0;
$posY = $ground_h - $h;
break;
case 8://8为底端居中
$posX = ($ground_w - $w) / 2;
$posY = $ground_h - $h;
break;
case 9://9为底端居右
$posX = $ground_w - $w;
$posY = $ground_h - $h;
break;
default://随机
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
}
//设定图像的混色模式
imagealphablending($ground_im, true);
if($isWaterImage)//图片水印
{
imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件
}
else//文字水印
{
if( !empty($textColor) && (strlen($textColor)==7) )
{
$R = hexdec(substr($textColor,1,2));
$G = hexdec(substr($textColor,3,2));
$B = hexdec(substr($textColor,5));
}
else
{
die("水印文字颜色格式不正确!");
}
imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
}
//生成水印后的图片
@unlink($product_img);
switch($ground_info[2])//取得背景图片的格式
{
case 1:imagegif($ground_im,$product_img);break;
case 2:imagejpeg($ground_im,$product_img);break;
case 3:imagepng($ground_im,$product_img);break;
default:die($errorMsg);
}
//释放内存
if(isset($water_info)) unset($water_info);
if(isset($water_im)) imagedestroy($water_im);
unset($ground_info);
imagedestroy($ground_im);
}
//---------------------------------------------------------------------------------------
if(isset($_FILES) && !empty($_FILES['userfile']) && $_FILES['userfile']['size']>0)
{
$uploadfile = "./".time()."_".$_FILES['userfile']['name'];
if (copy($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "OK<br>";
//文字水印
imageWaterMark($uploadfile,0,"","http://www.hi-pwr.com",5,"#FF0000");
//图片水印
//$waterImage="images/bz.gif";//水印图片路径
//imageWaterMark($uploadfile,0,$waterImage);
echo "<img src="".$uploadfile."" border="0">";
}
else
{
echo "Fail<br>";
}
}
php上传图片并生成缩位图代码,我们时常要上传图片,但也要保留自己的版权所以就会用到图片加水印哦,下面的程序就是上传图片成功后再给图片加上你自己做的水印效果哦.
<?php
class Image {
var $imageResource = NULL;
var $target = NULL;
var $enableTypes = array();
var $imageInfo = array();
var $createFunc = '';
var $imageType = NULL;
/**
* Construct for this class
*
* @param string $image
* @return Image
*/
function Image($image = NULL) {
//get enables
if(imagetypes() & IMG_GIF) {
$this->enableTypes[] = 'image/gif';
}
if(imagetypes() & IMG_JPEG) {
$this->enableTypes[] = 'image/jpeg';
}
if (imagetypes() & IMG_JPG) {
$this->enableTypes[] = 'image/jpg';
}
if(imagetypes() & IMG_PNG) {
$this->enableTypes[] = 'image/png';
}
//end get
if($image != NULL) {
$this->setImage($image);
}
}
/**
* set a image resource
*
* @param string $image
* @return boolean
*/
function setImage($image) {
if(file_exists($image) && is_file($image)) {
$this->imageInfo = getimagesize($image);
$img_mime = strtolower($this->imageInfo['mime']);
if(!in_array($img_mime, $this->enableTypes)) {
exit('系统不能操作这种图片类型.');
}
switch ($img_mime) {
case 'image/gif':
$link = imagecreatefromgif($image);
$this->createFunc = 'imagegif';
$this->imageType = 'gif';
break;
case 'image/jpeg':
case 'image/jpg':
$link = imagecreatefromjpeg($image);
$this->createFunc = 'imagejpeg';
$this->imageType = 'jpeg';
break;
case 'image/png':
$link = imagecreatefrompng($image);
$this->createFunc = 'imagepng';
$this->imageType = 'png';
break;
default:
$link = 'unknow';
$this->imageType = 'unknow';
break;
}
if($link !== 'unknow') {
$this->imageResource = $link;
} else {
exit('这种图片类型不能改变尺寸.');
}
unset($link);
return true;
} else {
return false;
}
}
/**
* set header
*
*/
function setHeader() {
switch ($this->imageType) {
case 'gif':
header('content-type:image/gif');
break;
case 'jpeg':
header('content-type:image/jpeg');
break;
case 'png':
header('content-type:image/png');
break;
default:
exit('Can not set header.');
break;
}
return true;
}
/**
* change the image size
*
* @param int $width
* @param int $height
* @return boolean
*/
function changeSize($width, $height = -1) {
if(!is_resource($this->imageResource)) {
exit('不能改变图片的尺寸,可能是你没有设置图片来源.');
}
$s_width = $this->imageInfo[0];
$s_height = $this->imageInfo[1];
$width = intval($width);
$height = intval($height);
if($width <= 0) exit('图片宽度必须大于零.');
if($height <= 0) {
$height = ($s_height / $s_width) * $width;
}
$this->target = imagecreatetruecolor($width, $height);
if(@imagecopyresized($this->target, $this->imageResource, 0, 0, 0, 0, $width, $height, $s_width, $s_height))
return true;
else
return false;
}
/**
* Add watermark
*
* @param string $image
* @param int $app
*/
function addWatermark($image, $app = 50) {
if(file_exists($image) && is_file($image)) {
$s_info = getimagesize($image);
} else {
exit($image . '文件不存在.');
}
$r_width = $s_info[0];
$r_height = $s_info[1];
if($r_width > $this->imageInfo[0]) exit('水印图片必须小于目标图片');
if($r_height > $this->imageInfo[1]) exit('水印图片必须小于目标图片');
switch ($s_info['mime']) {
case 'image/gif':
$resource = imagecreatefromgif($image);
break;
case 'image/jpeg':
case 'image/jpg':
$resource = imagecreatefromjpeg($image);
break;
case 'image/png':
$resource = imagecreatefrompng($image);
break;
default:
exit($s_info['mime'] .'类型不能作为水印来源.');
break;
}
$this->target = &$this->imageResource;
imagecopymerge($this->target, $resource, $this->imageInfo[0] - $r_width - 5, $this->imageInfo[1] - $r_height - 5, 0,0 ,$r_width, $r_height, $app);
imagedestroy($resource);
unset($resource);
}
/**
* create image
*
* @param string $name
* @return boolean
*/
function create($name = NULL) {
$function = $this->createFunc;
if($this->target != NULL && is_resource($this->target)) {
if($name != NULL) {
$function($this->target, $name);
} else {
$function($this->target);
}
return true;
} else if($this->imageResource != NULL && is_resource($this->imageResource)) {
if($name != NULL) {
$function($this->imageResource, $name);
} else {
$function($this->imageResource);
}
return true;
} else {
exit('不能创建图片,原因可能是没有设置图片来源.');
}
}
/**
* free resource
*
*/
function free() {
if(is_resource($this->imageResource)) {
@imagedestroy($this->imageResource);
}
if(is_resource($this->target)) {
@imagedestroy($this->target);
}
}
}
?>
ob_start();
$start = microtime(true);
$src = imagecreatefromjpeg($_GET["imageurl"]);
$width = imagesx($src);
$height = imagesy($src);
$dst = imagecreatetruecolor(160, 120);
imagecopyresampled($dst,$src,0,0,0,0,160,120,$width,$height);
header('Content-Type: image/jpeg');
imagejpeg($dst,'',100);
ob_end_clean();
echo microtime(true) - $start;
图片生成缩略图代码
<?php
# Constants
define("IMAGE_BASE", './');
define("MAX_WIDTH", 150);
define("MAX_HEIGHT", 150);
# Get image locationstr_replace('..', '', $_SERVER['QUERY_STRING']);
$image_file = 't.jpg';
$image_path = IMAGE_BASE . "$image_file";
# Load image
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($image_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
$img = @imagecreatefrompng($image_path);
}
# If an image was successfully loaded, test the image for size
if ($img) {
# Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);
# If the image is larger than the max shrink it
if ($scale < 1) {
$new_width =150; //floor($scale*$width);
$new_height =150;// floor($scale*$height);
# Create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
# Copy and resize old image into new image
imagecopyresized($tmp_img, $img, 0, 0, 0, 0,$new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
# Create error image if necessary
if (!$img) {
$img = imagecreate(MAX_WIDTH, MAX_HEIGHT);
imagecolorallocate($img,0,0,0);
$c = imagecolorallocate($img,70,70,70 );
imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2);
imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);
}
# Display the image
header("Content-type: image/jpeg");
imagejpeg($img);
imagedestroy($img);
?>
php生成 曲线图 程序
<?php
/*******************用法*************************
$gg=new build_graph();
$d1=array(0,62,25,20,20,100,99); //曲线一
//$d1=array('15'=>5,'16'=>8,'17'=>7,'18'=>9,'19'=>10,'20'=>15,'21'=>9); 改成这个形式啦
$d2=array(0,80,75,65,100,56,79); //曲线二
$d3=array(0,60,50,25,12,56,45); //曲线三 一下可以继续以此类推
$gg->add_data($d1);
$gg->add_data($d2);
$gg->add_data($d3);
$gg->set_colors("ee00ff,dd8800,00ff00"); //对应曲线的颜色
//生成曲线图
$gg->build("line",0); //参数0表示显示所有曲线,1为显示第一条,依次类推
//生成矩形图
//$gg->build("rectangle","2"); //参数0表示显示第一个矩形,1也为显示第一条,其余依次类推
///////////////////////////////////////////////////////////
//自定义图形显示,可任意图形叠加显示
header("Content-type: image/png");
$gg->create_cloths(); //画布
$gg->create_frame(); //画个框先
//$gg->build_rectangle(2); //画矩形
$gg->create_line(); //画线
$gg->build_line(0); //画曲线
imagepng($gg->image);
imagedestroy($gg->image);
*/
class build_graph {
var $graphwidth=300;
var $graphheight=300;
var $width_num=0; //宽分多少等分
var $height_num=10; //高分多少等分,默认为10
var $height_var=0; //高度增量(用户数据平均数)
var $width_var=0; //宽度增量(用户数据平均数)
var $height_max=0; //最大数据值
var $array_data=array(); //用户待分析的数据的二维数组
var $array_error=array(); //收集错误信息
var $colorBg=array(255,255,255); //图形背景-白色
var $colorGrey=array(192,192,192); //灰色画框
var $colorBlue=array(0,0,255); //蓝色
var $colorRed=array(255,0,0); //红色(点)
var $colorDarkBlue=array(0,0,255); //深色
var $colorLightBlue=array(200,200,255); //浅色
var $array_color; //曲线着色(存储十六进制数)
var $image; //我们的图像
//方法:接受用户数据
function add_data($array_user_data)
{
if(!is_array($array_user_data) or empty($array_user_data))
{
$this->array_error['add_data']="没有可供分析的数据";
return false;
exit();
}
$i=count($this->array_data);
$this->array_data[$i]=$array_user_data;
}
//方法:定义画布宽和长
function set_img($img_width,$img_height){
$this->graphwidth=$img_width;
$this->graphheight=$img_height;
}
//设定Y轴的增量等分,默认为10份
function set_height_num($var_y){
$this->height_num=$var_y;
}
//定义各图形各部分色彩
function get_RGB($color){ //得到十进制色彩
$R=($color>>16) & 0xff;
$G=($color>>8) & 0xff;
$B=($color) & 0xff;
return (array($R,$G,$B));
}
//---------------------------------------------------------------
#定义背景色
function set_color_bg($c1,$c2,$c3){
$this->colorBg=array($c1,$c2,$c3);
}
#定义画框色
function set_color_Grey($c1,$c2,$c3){
$this->colorGrey=array($c1,$c2,$c3);
}
#定义蓝色
function set_color_Blue($c1,$c2,$c3){
$this->colorBlue=array($c1,$c2,$c3);
}
#定义色Red
function set_color_Red($c1,$c2,$c3){
$this->colorRed=array($c1,$c2,$c3);
}
#定义深色
function set_color_DarkBlue($c1,$c2,$c3){
$this->colorDarkBlue=array($c1,$c2,$c3);
}
#定义浅色
function set_color_LightBlue($c1,$c2,$c3){
$this->colorLightBlue=array($c1,$c2,$c3);
}
//---------------------------------------------------------------
//方法:由用户数据将画布分成若干等份宽
//并计算出每份多少像素
function get_width_num(){
$this->width_num=count($this->array_data[0]);
}
function get_max_height(){
//获得用户数据的最大值
$tmpvar=array();
foreach($this->array_data as $tmp_value)
{
$tmpvar[]=max($tmp_value);
}
$this->height_max=max($tmpvar);
return max($tmpvar);
}
function get_height_length(){
//计算出每格的增量长度(用户数据,而不是图形的像素值)
$max_var=$this->get_max_height();
$max_var=round($max_var/$this->height_num);
$first_num=substr($max_var,0,1);
if(substr($max_var,1,1)){
if(substr($max_var,1,1)>=5)
$first_num+=1;
}
for($i=1;$i<strlen($max_var);$i++){
$first_num.="0";
}
return (int)$first_num;
}
function get_var_wh() //得到高和宽的增量
{
$this->get_width_num();
//得到高度增量和宽度增量
$this->height_var=$this->get_height_length();
$this->width_var=round($this->graphwidth/$this->width_num);
}
function set_colors($str_colors){
//用于多条曲线的不同着色,如$str_colors="ee00ff,dd0000,cccccc"
$this->array_color=split(",",$str_colors);
}
######################################################################################################
function build_line($var_num)
{
if(!empty($var_num))
{ //如果用户只选择显示一条曲线
$array_tmp[0]=$this->array_data[$var_num-1];
$this->array_data=$array_tmp;
}
//画线
for($j=0;$j<count($this->array_data);$j++)
{
list($R,$G,$B)=$this->get_RGB(hexdec($this->array_color[$j]));
$colorBlue=imagecolorallocate($this->image,$R,$G,$B);
$i=0;
foreach($this->array_data[$j] as $keys=>$values)
{
$height_next_pix[]=round($this->array_data[$j][$keys]/$this->height_max*$this->graphheight);
}
foreach($this->array_data[$j] as $key=>$value)
{
$height_pix=round(($this->array_data[$j][$key]/$this->height_max)*$this->graphheight);
if($i!=count($this->array_data[$j])-1)
{
imageline($this->image,$this->width_var*$i,$this->graphheight-$height_pix,$this->width_var*($i+1),$this->graphheight-$height_next_pix[$i+1],$colorBlue);
}
$i++;
}
//print_r($height_next_pix);
// exit;
/*
for($i=0;$i<$this->width_num-1;$i++)
{
$height_pix=round(($this->array_data[$j][$i]/$this->height_max)*$this->graphheight);
$height_next_pix=round($this->array_data[$j][$i+1]/$this->height_max*$this->graphheight);
imageline($this->image,$this->width_var*$i,$this->graphheight-$height_pix,$this->width_var*($i+1),$this->graphheight-$height_next_pix,$colorBlue);
}*/
}
//画点
$colorRed=imagecolorallocate($this->image, $this->colorRed[0], $this->colorRed[1], $this->colorRed[2]);
for($j=0;$j<count($this->array_data);$j++)
{
$i=0;
foreach($this->array_data[$j] as $key=>$value)
{
$height_pix=round(($this->array_data[$j][$key]/$this->height_max)*$this->graphheight);
imagearc($this->image,$this->width_var*$i,$this->graphheight-$height_pix,6,5,0,360,$colorRed);
imagefilltoborder($this->image,$this->width_var*$i,$this->graphheight-$height_pix,$colorRed,$colorRed);
$i++;
}
/*
for($i=0;$i<$this->width_num;$i++)
{
$height_pix=round(($this->array_data[$j][$i]/$this->height_max)*$this->graphheight);
imagearc($this->image,$this->width_var*$i,$this->graphheight-$height_pix,6,5,0,360,$colorRed);
imagefilltoborder($this->image,$this->width_var*$i,$this->graphheight-$height_pix,$colorRed,$colorRed);
}
*/
}
}
######################################################################################################
function build_rectangle($select_gra){
if(!empty($select_gra)){ //用户选择显示一个矩形
$select_gra-=1;
}
//画矩形
//配色
$colorDarkBlue=imagecolorallocate($this->image, $this->colorDarkBlue[0], $this->colorDarkBlue[1], $this->colorDarkBlue[2]);
$colorLightBlue=imagecolorallocate($this->image, $this->colorLightBlue[0], $this->colorLightBlue[1], $this->colorLightBlue[2]);
if(empty($select_gra))
$select_gra=0;
for($i=0; $i<$this->width_num; $i++){
$height_pix=round(($this->array_data[$select_gra][$i]/$this->height_max)*$this->graphheight);
imagefilledrectangle($this->image,$this->width_var*$i,$this->graphheight-$height_pix,$this->width_var*($i+1),$this->graphheight, $colorDarkBlue);
imagefilledrectangle($this->image,($i*$this->width_var)+1,($this->graphheight-$height_pix)+1,$this->width_var*($i+1)-5,$this->graphheight-2, $colorLightBlue);
}
}
######################################################################################################
function create_cloths(){
//创建画布
$this->image=imagecreate($this->graphwidth+20,$this->graphheight+20);
}
function create_frame(){
//创建画框
$this->get_var_wh();
//配色
$colorBg=imagecolorallocate($this->image, $this->colorBg[0], $this->colorBg[1], $this->colorBg[2]);
$colorGrey=imagecolorallocate($this->image, $this->colorGrey[0], $this->colorGrey[1], $this->colorGrey[2]);
//创建图像周围的框
imageline($this->image, 0, 0, 0, $this->graphheight,$colorGrey);
imageline($this->image, 0, 0, $this->graphwidth, 0,$colorGrey);
imageline($this->image, ($this->graphwidth-1),0,($this->graphwidth-1),($this->graphheight-1),$colorGrey);
imageline($this->image, 0,($this->graphheight-1),($this->graphwidth-1),($this->graphheight-1),$colorGrey);
}
function create_line()
{
//创建网格。
$this->get_var_wh();
$colorBg=imagecolorallocate($this->image, $this->colorBg[0], $this->colorBg[1], $this->colorBg[2]);
$colorGrey=imagecolorallocate($this->image, $this->colorGrey[0], $this->colorGrey[1], $this->colorGrey[2]);
$colorRed=imagecolorallocate($this->image, $this->colorRed[0], $this->colorRed[1], $this->colorRed[2]);
for($i=1;$i<=$this->height_num;$i++)
{
//画横线
$y1=($this->graphheight-($this->height_var/$this->height_max*$this->graphheight)*$i);
$y2=($this->graphheight-($this->height_var/$this->height_max*$this->graphheight)*$i);
imageline($this->image,0,$y1,$this->graphwidth,$y2,$colorGrey);
//标出数字
imagestring($this->image,2,0,$this->graphheight-($this->height_var/$this->height_max*$this->graphheight)*$i,$this->height_var*$i,$colorRed);
}
unset($i);
foreach($this->array_data[0] as $key=>$value)
{
//画竖线
imageline($this->image,$this->width_var*$i,0,$this->width_var*$i,$this->graphwidth,$colorGrey);
//标出数字
imagestring($this->image,2,$this->width_var*$i,$this->graphheight-15,$key,$colorRed);
$i++;
}
/*
for($i=1;$i<=$this->width_num;$i++)
{
//画竖线
imageline($this->image,$this->width_var*$i,0,$this->width_var*$i,$this->graphwidth,$colorGrey);
//标出数字
imagestring($this->image,2,$this->width_var*$i,$this->graphheight-15,$i,$colorRed);
}
*/
}
function build($graph,$str_var){
//$graph是用户指定的图形种类,$str_var是生成哪个数据的图
header("Content-type: image/jpeg");
$this->create_cloths(); //先要有画布啊~~
switch ($graph){
case "line":
$this->create_frame(); //画个框先:)
$this->create_line(); //打上底格线
$this->build_line($str_var); //画曲线
break;
case "rectangle":
$this->create_frame(); //画个框先:)
$this->build_rectangle($str_var); //画矩形
$this->create_line(); //打上底格线
break;
}
//输出图形并清除内存
imagepng($this->image);
imagedestroy($this->image);
}
}
?>
相关文章
- 这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
- 本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
- 这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
- PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
- 这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
- 本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
- 大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
- 这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
- 这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
- index.php怎么打开?初学者可能不知道如何打开index.php,不会的同学可以参考一下本篇教程 打开编辑:右键->打开方式->经文本方式打开打开运行:首先你要有个支持运行PH...2017-07-06
将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文
时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
- 这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
- 这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
PHP中func_get_args(),func_get_arg(),func_num_args()的区别
复制代码 代码如下:<?php function jb51(){ print_r(func_get_args()); echo "<br>"; echo func_get_arg(1); echo "<br>"; echo func_num_args(); } jb51("www","j...2013-10-04- 这篇文章主要介绍了PHP编程 SSO详细介绍及简单实例的相关资料,这里介绍了三种模式跨子域单点登陆、完全跨单点域登陆、站群共享身份认证,需要的朋友可以参考下...2017-01-25
- 这篇文章主要为大家详细介绍了微信小程序实现点击导航条切换页面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-19
- 这篇文章主要介绍了微信小程序手势操作之单触摸点与多触摸点的相关资料,需要的朋友可以参考下...2017-03-13
- 这篇文章主要为大家详细介绍了微信小程序实现canvas分享朋友圈海报,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-21