php生成饼图效果的实现代码

 更新时间:2016年11月25日 16:24  点击:1621
生成饼图很多代码都可以实现,今天我们介绍的这个实例是基于php gd库的一种生成统计数据的饼图效果,有需要的同学可以参考一下。
 代码如下 复制代码
<?
//+------------------------+
//| pie3dfun.PHP//公用函数 |
//+------------------------+
define("ANGLE_STEP", 5); //定义画椭圆弧时的角度步长
function draw_getdarkcolor($img,$clr) //求$clr对应的暗色
{
$rgb = imagecolorsforindex($img,$clr);
return array($rgb["red"]/2,$rgb["green"]/2,$rgb["blue"]/2);
}
function draw_getexy($a, $b, $d) //求角度$d对应的椭圆上的点坐标
{
$d = deg2rad($d);
return array(round($a*Cos($d)), round($b*Sin($d)));
}
function draw_arc($img,$ox,$oy,$a,$b,$sd,$ed,$clr) //椭圆弧函数
{
$n = ceil(($ed-$sd)/ANGLE_STEP);
$d = $sd;
list($x0,$y0) = draw_getexy($a,$b,$d);
for($i=0; $i<$n; $i++)
{
$d = ($d+ANGLE_STEP)>$ed?$ed:($d+ANGLE_STEP);
list($x, $y) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr);
$x0 = $x;
$y0 = $y;
}
}
function draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr) //画扇面
{
$n = ceil(($ed-$sd)/ANGLE_STEP);
$d = $sd;
list($x0,$y0) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox, $y0+$oy, $ox, $oy, $clr);
for($i=0; $i<$n; $i++)
{
$d = ($d+ANGLE_STEP)>$ed?$ed:($d+ANGLE_STEP);
list($x, $y) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr);
$x0 = $x;
$y0 = $y;
}
imageline($img, $x0+$ox, $y0+$oy, $ox, $oy, $clr);
list($x, $y) = draw_getexy($a/2, $b/2, ($d+$sd)/2);
imagefill($img, $x+$ox, $y+$oy, $clr);
}
function draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clr) //3d扇面
{
draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr);
if($sd<180)
{
list($R, $G, $B) = draw_getdarkcolor($img, $clr);
$clr=imagecolorallocate($img, $R, $G, $B);
if($ed>180) $ed = 180;
list($sx, $sy) = draw_getexy($a,$b,$sd);
$sx += $ox;
$sy += $oy;
list($ex, $ey) = draw_getexy($a, $b, $ed);
$ex += $ox;
$ey += $oy;
imageline($img, $sx, $sy, $sx, $sy+$v, $clr);
imageline($img, $ex, $ey, $ex, $ey+$v, $clr);
draw_arc($img, $ox, $oy+$v, $a, $b, $sd, $ed, $clr);
list($sx, $sy) = draw_getexy($a, $b, ($sd+$ed)/2);
$sy += $oy+$v/2;
$sx += $ox;
imagefill($img, $sx, $sy, $clr);
}
}
function draw_getindexcolor($img, $clr) //RBG转索引色
{
$R = ($clr>>16) & 0xff;
$G = ($clr>>8)& 0xff;
$B = ($clr) & 0xff;
return imagecolorallocate($img, $R, $G, $B);
}
// 绘图主函数,并输出图片
// $datLst 为数据数组, $datLst 为标签数组, $datLst 为颜色数组
// 以上三个数组的维数应该相等
function draw_img($datLst,$labLst,$clrLst,$a=250,$b=120,$v=20,$font=10)
{
$ox = 5+$a;
$oy = 5+$b;
$fw = imagefontwidth($font);
$fh = imagefontheight($font);
$n = count($datLst);//数据项个数
$w = 10+$a*2;
$h = 10+$b*2+$v+($fh+2)*$n;
$img = imagecreate($w, $h);
//转RGB为索引色
for($i=0; $i<$n; $i++)
$clrLst[$i] = draw_getindexcolor($img,$clrLst[$i]);
$clrbk = imagecolorallocate($img, 0xff, 0xff, 0xff);
$clrt = imagecolorallocate($img, 0x00, 0x00, 0x00);
//填充背景色
imagefill($img, 0, 0, $clrbk);
//求和
$tot = 0;
for($i=0; $i<$n; $i++)
$tot += $datLst[$i];
$sd = 0;
$ed = 0; 333
$ly = 10+$b*2+$v;
for($i=0; $i<$n; $i++)
{
$sd = $ed;
$ed += $datLst[$i]/$tot*360;
//画圆饼
draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clrLst[$i]); //$sd,$ed,$clrLst[$i]);
//画标签
imagefilledrectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrLst[$i]);
imagerectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrt);
//imagestring($img, $font, 5+2*$fw, $ly, $labLst[$i].":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)", $clrt);
$str = iconv("GB2312", "UTF-8", $labLst[$i]);
ImageTTFText($img, $font, 0, 5+2*$fw, $ly+13, $clrt, "./simsun.ttf", $str.":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)");
$ly += $fh+2;
}
//输出图形
header("Content-type: image/png");
//输出生成的图片
$imgFileName = "../temp/".time().".png";
imagepng($img,$imgFileName);
echo '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
$datLst = array(30, 10, 20, 20, 10, 20, 10, 20); //数据
$labLst = array("中国科技大学", "安徽理工大学", "清华大学", "北京大学", "南京大学", "上海大学", "河海大学", "中山大学"); //标签
$clrLst = array(0x99ff00, 0xff6666, 0x0099ff, 0xff99ff, 0xffff99, 0x99ffff, 0xff3333, 0x009999);
//画图
draw_img($datLst,$labLst,$clrLst);
?>

效果图如下

下面详细讲到了几点。 1、点击登录跳转到SSO登录页面并带上当前应用的callback地址 2、登录成功后生成COOKIE并将COOKIE传给callback地址 3、callback地址接收SSO的COOKIE并设置在当前域下再跳回到应用1即完成登录 4、再在应用程序需要登录的地方嵌入一个iframe用来实时检测登录状态
 代码如下 复制代码

 


<?php
//index.php 应用程序页面
header('Content-Type:text/html; charset=utf-8');
$sso_address = 'http://2spaoku.com/sso/login.php'; //你SSO所在的域名
$callback_address = 'http://'.$_SERVER['HTTP_HOST']
                    .str_replace('index.php','',$_SERVER['SCRIPT_NAME'])
                    .'callback.php'; //callback地址用于回调设置cookie

if(isset($_COOKIE['sign'])){
    exit("欢迎您{$_COOKIE['sign']} <a href="login.php?logout">退出</a>");
}else{
    echo '您还未登录 <a href="'.$sso_address.'?callback='.$callback_address.'">点此登录</a>';
}
?>
<iframe src="<?php echo $sso_address ?>?callback=<?php echo $callback_address ?>" frameborder="0"  width="0" height="0"></iframe>

<?php
//login.php SSO登录页面
header('Content-Type:text/html; charset=utf-8');
if(isset($_GET['logout'])){
    setcookie('sign','',-300);
    unset($_GET['logout']);
    header('location:index.php');
}

if(isset($_POST['username']) && isset($_POST['password'])){
    setcookie('sign',$_POST['username'],0,'');
    header("location:".$_POST['callback']."?sign={$_POST['username']}");
}

if(empty($_COOKIE['sign'])){
?>

<form method="post">
<p>用户名:<input type="text" name="username" /></p>
<p>密  码:<input type="password" name="password" /></p>
<input type="hidden" name="callback" value="<?php echo $_GET['callback']; ?>" />
<input type="submit" value="登录" />
</form>


<?php
}else{
    $query = http_build_query($_COOKIE);
    echo "系统检测到您已登录 {$_COOKIE['sign']} <a href="{$_GET['callback']}?{$query}">授权</a> <a href="?logout">退出</a>";
}
?>

<?php
//callback.php 回调页面用来设置跨域COOKIE
header('Content-Type:text/html; charset=utf-8');
if(empty($_GET)){
    exit('您还未登录');
}else{
    foreach($_GET as $key=>$val){
        setcookie($key,$val,0,'');
    }
    header("location:index.php");
}
?>

<?php
//connect.php 用来检测登录状态的页面,内嵌在页面的iframe中
header('Content-Type:text/html; charset=utf-8');
if(isset($_COOKIE['sign'])){
    $callback = urldecode($_GET['callback']);unset($_GET['callback']);
    $query = http_build_query($_COOKIE);
    $callback = $callback."?{$query}";
}else{
    exit;
}
?>
<html><script type="text/javascript">top.location.href="<?php echo $callback; ?>";</script></html>

 

一篇关于提高php程序性能和负载测试的实例代码,有需要的朋友可以看看如何提高自己程序的性能哦。

计算执行的时间
通过下面这个简单的方法可以计算一段程序的执行时间(微妙)

 代码如下 复制代码

$start_time = microtime(true);

//一些需要计算时间的代码
//... code here ...

print('代码的运行时间是:'.getExecTime($start_time));

function getExecTime($start_time)
{
 return microtime(true)-$start_time;
}PEAR的Benchmark模块提供了更详细的时间统计功能

require_once 'Benchmark/Timer.php';
$timer =& new Benchmark_Timer(true);
$timer->start();
// 设置函数
$timer->setMarker('setup');
// some more code executed here
$timer->setMarker('middle');
// even yet still more code here
$timer->setmarker('done');
// and a last bit of code here
$timer->stop();
$timer->display();通过declare结构和ticks指令可以实现自动记录每一行PHP代码执行的时间

// A function that records the time when it is called
function profile($dump = FALSE)
{
    static $profile;

    // Return the times stored in profile, then erase it
    if ($dump) {
        $temp = $profile;
        unset($profile);
        return ($temp);
    }

    $profile[] = microtime();
}

// Set up a tick handler
register_tick_function("profile");

// Initialize the function before the declare block
profile();

// Run a block of code, throw a tick every 2nd statement
declare(ticks=2) {
    for ($x = 1; $x < 50; ++$x) {
        echo similar_text(md5($x), md5($x*$x)), ";";
    }
}

// Display the data stored in the profiler
print_r(profile (TRUE));注意:ticks 指令在 PHP 5.3.0 中是过时指令,将会从 PHP 6.0.0 移除。

代码排错
主要介绍的是Advanced PHP Debugger(APD),通过设置可以生成跟踪文件,对文件进行分析可以得到脚本的详细信息

网站压力测试
人们常混淆压力测试和基准测试。基准测试是一种由单独的开发者完成的临时活动,常用Apache HTTP测试工具——ab,该工具可以测试一台HTTP服务器每秒能相应的请求数。压力测试是一种能中断你WEB应用程序的测试技术,通过对断点测试,能识别并修复应用程序中的弱点,为何时购置新硬件提供依据。常用的开源工具是Siege。

提速技巧
通过安装PHP加速器可以有效的提供PHP的执行速度,常见的三种加速器是Alternative PHP Cache(APC)、eAccelerator和ionCube PHP Accelerator(PHPA)。另外需要注意的是加速器的兼容性通常会滞后于新发布的PHP版本。

另外提速技巧是在能不使用正则的时候尽量不要用,通常可替代的方案会比使用正则效率更高。

要实现记住密码自动登录的功能我们大多数据都是利用了客户端的cookies来实现,我们利用php也不例外,有需要的朋友可以参考一下。

php制作记住密码自动登录的解决思路,其实也就是对session,cookies的操作
//检查用户是否登录 

 代码如下 复制代码
function checklogin(){ 
     if(empty($_SESSION['user_info'])){    //检查一下session是不是为空 
     if(empty($_COOKIE['username']) || empty($_COOKIE['password'])){  //如果session为空,并且用户没有选择记录登录状 
     header("location:login.php?req_url=".$_SERVER['REQUEST_URI']);  //转到登录页面,记录请求的url,登录后跳转过去,用户体验好。 
}else{   //用户选择了记住登录状态 
     $user = getUserInfo($_COOKIE['username'],$_COOKIE['password']);   //去取用户的个人资料 
     if(empty($user)){    //用户名密码不对没到取到信息,转到登录页面 
     header("location:login.php?req_url=".$_SERVER['REQUEST_URI']); 
     }else{ 
     $_SESSION['user_info'] = $user;   //用户名和密码对了,把用户的个人资料放到session里面 
     } 
     } 
     } 
}


二,用户提交登录信息

 代码如下 复制代码
username = trim($_POST['username']); 
$password = md5(trim($_POST['password'])); 
$validatecode = $_POST['validateCode']; 
$ref_url = $_GET['req_url']; 
$remember = $_POST['remember']; 
 
$err_msg = ''; 
if($validatecode!=$_SESSION['checksum']){ 
$err_msg = "验证码不正确"; 
}elseif($username=='' || $password==''){ 
$err_msg = "用户名和密码都不能为空"; 
}else{ 
$row = getUserInfo($username,$password); 
 
if(empty($row)){ 
$err_msg = "用户名和密码都不正确"; 
}else{ 
$_SESSION['user_info'] = $row; 
if(!empty($remember)){     //如果用户选择了,记录登录状态就把用户名和加了密的密码放到cookie里面 
setcookie("username", $username, time()+3600*24*365); 
setcookie("password", $password, time()+3600*24*365); 

if(strpos($ref_url,"login.php") === false){ 
header("location:".$ref_url); 
}else{ 
header("location:main_user.php"); 


}


三,当用户点退出时,清出记录登录状态


//退出登录 

 代码如下 复制代码
function logout(){ 
unset($_SESSION['user_info']); 
if(!empty($_COOKIE['username']) || !empty($_COOKIE['password'])){ 
setcookie("username", null, time()-3600*24*365); 
setcookie("password", null, time()-3600*24*365); 

}
分享一个网友写的php图片上传类,支持加水印,生成略缩图功能哦,面是配置和可以获取的一些信息(每一个配置信息都有默认值,如无特殊需要,可以不配置):
 代码如下 复制代码

<?php
/*----------------------------------------------------------------------------------
 *
 *----------------------------------------------------------------------------------
 */
class image_up{
 //定义基本参数
 private $uptype=array('image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp','image/x-png');  //上传文件类型
 private $max_file_size=102400;    //上传大小限制(单位:KB)
 private $destination_folder="up/"; //上传文件路径
 private $watermark=1;              //是否附加水印
 private $watertype=1;              //水印类型(1为文字,2为图片)
 private $waterposition=1;          //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);
 private $waterstring=null;         //水印字符串
 private $waterimg=null;            //水印图片
 private $imgpreview=1;             //是否生成预览图(1为生成,其他为不生成);
 private $imgpreviewsize=1;         //预览图比例,0为按固定宽和高显示,其他为比例显示
 private $imgwidth=200;             //预览图固定宽度
 private $imgheight=200;            //预览图固定高度
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 private $imgthu=1;                     //是否生成且保存略缩图,1为生成,0为不生成
 private $imgthu_folder=null;           //略缩图保存路径,默认与文件路径一致
 private $imgthu_fixed=0;               //略缩图是否使用固定宽高,1为使用,0为灵活变动
 private $imgthu_width=200;             //略缩图宽度
 private $imgthu_height=200;            //略缩图高度
 
 private $imgthu_name=null;             //略缩图名称
 //******************************************************************************************************************
 private $inputname="upfile";       //文件上传框名称
 //******************************************************************************************************************
 private $img_preview_display;      //图片预览图显示
 //******************************************************************************************************************
 //文件上传相关信息,1为文件不存在,2为类型不符合,3为超出大小限制,4为上传失败,0为上传成功
 private $file_up_info=null;
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 //可在外部获取上传文件基本信息
 private $file_name;         //客服端文件的原名称
 private $file_type;         //文件的MIME类型
 private $file_size;         //已上传文件的大小,单位/字节
 private $file_tmp_name;     //储存的临时文件名
 private $file_error;        //该文件上传相关错误代码

 private $img_size;          //取得图片的长宽
 private $file_basename;     //获取带扩展名的全名
 private $file_extension;    //获取文件扩展名
 private $filename;          //文件名(不带扩展名)
 private $destination;       //问价路径加名称
 //******************************************************************************************************************
 public function __set($propety_name,$value){
  $this->$propety_name=$value;
 }
 public function __get($property_name){
  if(isset($this->$property_name))
  return($this->$property_name);
  else return(NULL);
 }
 //******************************************************************************************************************
 //定义文件上传功能
 public function up(){
  //判断文件是否存在
  if(!is_uploaded_file($_FILES[$this->inputname]["tmp_name"])){
   $this->file_up_info=1;
   return;
  }
  //获取并赋值相应基本参数
  $upfile=$_FILES[$this->inputname];
  $this->file_name=$upfile["name"];
  $this->file_type=$upfile["type"];
  $this->file_size=$upfile["size"];
  $this->file_tmp_name=$upfile["tmp_name"];
  $this->file_error=$upfile["error"];
  //检查文件类型是否符合
  if(!in_array($this->file_type,$this->uptype)){
   $this->file_up_info=2;
   return;
  }
  //检查文件大小是否超出限制
  if($this->file_size>$this->max_file_size){
   $this->file_up_info=3;
   return;
  }
  //判断目录是否存在
  if(!file_exists($this->destination_folder))
  mkdir($this->destination_folder);
  //进一步取得图片的信息并赋值
  $this->img_size=getimagesize($this->file_tmp_name);
  $pathinfo=pathinfo($this->file_name);
  $this->file_extension=$pathinfo["extension"];    //获取文件扩展名
  $this->file_basename=$pathinfo["basename"];      //获取带扩展名的全名
  $this->filename=$pathinfo["filename"];           //文件名(不带扩展名)
  $filename2=$pathinfo['filename'];
  $this->destination = $this->destination_folder.$this->filename.".".$this->file_extension;
  //判断文件名是否存在,如果存在则重命名
  $n=1;
  while (file_exists($this->destination)){
   while (file_exists($this->destination)){
    $n++;
    $this->filename=$this->filename."(".$n.")";
    $this->destination = $this->destination_folder.$this->filename.".".$this->file_extension;
   }
   $this->filename=$filename2."(".$n.")";
   $this->destination = $this->destination_folder.$this->filename.".".$this->file_extension;
  }
  //移动上传的文件
  if(move_uploaded_file($this->file_tmp_name,$this->destination))
  $this->file_up_info=0;
  else $this->file_up_info=4;
   
  //添加水印
  if($this->watermark==1){
   $this->imgthu();
  }
  //生成略缩图
  if($this->imgthu==1){
   $this->add_watermark();
  }
  //生成预览图
  if($this->imgpreviewsize == 0){
   if($this->img_size["0"]<$this->imgwidth) $this->imgwidth=$this->img_size["0"];
   if($this->img_size["1"]<$this->imgheight) $this->imgheight=$this->img_size["1"];
  }else{
   $this->imgwidth=$this->img_size["0"]*$this->imgpreviewsize;
   $this->imgheight=$this->img_size["1"]*$this->imgpreviewsize;
  }
  $this->img_preview_display="<img src='$this->destination' width='$this->imgwidth' height='$this->imgheight'
                                    alt='图片预览:r文件名':$this->file_tmp_name />";
 }
//====================================================================================================================
//==================================================================================================================== 
 //生成略缩图功能
 function imgthu(){
  if($this->imgthu_folder==null)
    $this->imgthu_folder=$this->destination_folder;
  
  //$this->imgthu_name=$this->filename."_t.".$this->file_extension;
  $imgthu_name_b=$this->filename."_t";
  $imgthu_name_b2=$this->filename."_t";
  $destination_b=$this->imgthu_folder.$imgthu_name_b.".".$this->file_extension;
     //判断文件名是否存在,如果存在则重命名
  $n=1;
  while (file_exists($destination_b)){
   while (file_exists($destination_b)){
    $n++;
    $imgthu_name_b=$imgthu_name_b."(".$n.")";
    $destination_b = $this->imgthu_folder.$imgthu_name_b.".".$this->file_extension;
   }
   $imgthu_name_b=$imgthu_name_b2."(".$n.")";
   $destination_b = $this->imgthu_folder.$imgthu_name_b.".".$this->file_extension;
  }
  
  
  $imginfo=getimagesize($this->destination);
  switch($imginfo[2])
  {
   case 1:
    $in=@imagecreatefromgif($this->destination);
    break;
   case 2:
    $in=@imagecreatefromjpeg($this->destination);
    break;
   case 3:
    $in=@imagecreatefrompng($this->destination);
    break;
   case 6:
    $in =@imagecreatefrombmp($this->destination);
    break;
   default:
    break;
  }
  //计算略缩图长宽
  if($this->imgthu_fixed==0){
   if($this->imgthu_height>($imginfo[1]/$imginfo[0])*$this->imgthu_width)
    $this->imgthu_width = ($imginfo[0]/$imginfo[1])*$this->imgthu_height;
   else
    $this->imgthu_height=($imginfo[1]/$imginfo[0])*$this->imgthu_width;
  }
  $new = imageCreateTrueColor($this->imgthu_width,$this->imgthu_height);
  ImageCopyResized($new,$in,0,0,0,0,$this->imgthu_width,$this->imgthu_height,$imginfo[0],$imginfo[1]);
  switch ($imginfo[2])
  {
   case 1:
    imagejpeg($new,$destination_b);
    break;
   case 2:
    imagejpeg($new,$destination_b);
    break;
   case 3:
    imagepng($new,$destination_b);
    break;
   case 6:
    imagewbmp($new,$destination_b);
    break;
  }
 }
//====================================================================================================================
//==================================================================================================================== 
 //添加水印功能
 function add_watermark(){
  //1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),
  //8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。
  $imginfo=getimagesize($this->destination);
  $im=imagecreatetruecolor($this->img_size[0],$this->img_size[1]);       //创建真彩色
  $white=imagecolorallocate($im,255,255,255);                            //设置颜色
  $black=imagecolorallocate($im,0,0,0);
  $red=imagecolorallocate($im,255,0,0);
  //在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。
  imagefill($im,0,0,$white);

  switch($imginfo[2])
  {
   case 1:
    $simage =imagecreatefromgif($this->destination);      // 创建一个新的形象,从文件或 URL
    break;
   case 2:
    $simage =imagecreatefromjpeg($this->destination);
    break;
   case 3:
    $simage =imagecreatefrompng($this->destination);
    break;
   case 6:
    $simage =imagecreatefromwbmp($this->destination);
    break;
   default:
    echo ("不支持的文件类型");
    break;
  }
  if(!empty($simage))
  {
   //位置设置
   if($this->watertype==1){
    $str_len=strlen($this->waterstring);
       $str_width=$str_len*10;
       $str_height=20;
   }elseif($this->watertype==1 && file_exists($this->waterimg)){
    $iinfo=getimagesize($this->waterimg);
    $str_width = $iinfo[0];
    $str_height = $iinfo[1];
   }
   
   switch ($this->waterposition){
    case 1:
     $p_x=5;
     $p_y=$this->img_size[1]-$str_height;
     break;
    case 2:
     $p_x=$this->img_size[0]-$str_width;
     $p_y=$this->img_size[1]-$str_height;
     break;
    case 3:
     $p_x=5;
     $p_y=0;
     break;
    case 4:
     $p_x=$this->img_size[0]-$str_width;
     $p_y=5;
     break;
    case 5:
     $p_x=($this->img_size[0]-$str_width)/2;
     $p_y=($this->img_size[1]-$str_height)/2;
     break;
   }
   imagecopy($im,$simage,0,0,0,0,$this->img_size[0],$this->img_size[1]);   //拷贝图像的一部分
   //imagefilledrectangle($im,1,$this->img_size[1]-15,130,$this->img_size[1],$white);  //将图片的封闭长方形区域着色

   switch($this->watertype)
   {
    case 1:   //加水印字符串
     imagestring($im,10,$p_x,$p_y,$this->waterstring,$red);
     break;
    case 2:   //加水印图片
     $simage1 =imagecreatefromgif($this->waterimg);
     imagecopy($im,$simage1,0,0,0,0,85,15);
     imagedestroy($simage1);
     break;
   }

   switch ($imginfo[2])
   {
    case 1:
     //imagegif($nimage, $destination);
     imagejpeg($im, $this->destination);
     break;
    case 2:
     imagejpeg($im, $this->destination);
     break;
    case 3:
     imagepng($im, $this->destination);
     break;
    case 6:
     imagewbmp($im, $this->destination);
     break;
   }
   //覆盖原上传文件
   imagedestroy($im);
   imagedestroy($simage);
  }
 }
}
?>

[!--infotagslink--]

相关文章

  • php语言实现redis的客户端

    php语言实现redis的客户端与服务端有一些区别了因为前面介绍过服务端了这里我们来介绍客户端吧,希望文章对各位有帮助。 为了更好的了解redis协议,我们用php来实现...2016-11-25
  • jQuery+jRange实现滑动选取数值范围特效

    有时我们在页面上需要选择数值范围,如购物时选取价格区间,购买主机时自主选取CPU,内存大小配置等,使用直观的滑块条直接选取想要的数值大小即可,无需手动输入数值,操作简单又方便。HTML首先载入jQuery库文件以及jRange相关...2015-03-15
  • 不打开网页直接查看网站的源代码

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • JS实现的简洁纵向滑动菜单(滑动门)效果

    本文实例讲述了JS实现的简洁纵向滑动菜单(滑动门)效果。分享给大家供大家参考,具体如下:这是一款纵向布局的CSS+JavaScript滑动门代码,相当简洁的手法来实现,如果对颜色不满意,你可以试着自己修改CSS代码,这个滑动门将每一...2015-10-21
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • JS实现自定义简单网页软键盘效果代码

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • php 取除连续空格与换行代码

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • PHP实现清除wordpress里恶意代码

    公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
  • js识别uc浏览器的代码

    其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
  • JS实现双击屏幕滚动效果代码

    本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
  • jQuery+slidereveal实现的面板滑动侧边展出效果

    我们借助一款jQuery插件:slidereveal.js,可以使用它控制面板左右侧滑出与隐藏等效果,项目地址:https://github.com/nnattawat/slideReveal。如何使用首先在页面中加载jquery库文件和slidereveal.js插件。复制代码 代码如...2015-03-15
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP+jQuery翻板抽奖功能实现

    翻板抽奖的实现流程:前端页面提供6个方块,用数字1-6依次表示6个不同的方块,当抽奖者点击6个方块中的某一块时,方块翻转到背面,显示抽奖中奖信息。看似简单的一个操作过程,却包含着WEB技术的很多知识面,所以本文的读者应该熟...2015-10-21
  • PHP开发微信支付的代码分享

    微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
  • php二维码生成

    本文介绍两种使用 php 生成二维码的方法。 (1)利用google生成二维码的开放接口,代码如下: /** * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】 * @param strin...2015-10-21
  • Java生成随机姓名、性别和年龄的实现示例

    这篇文章主要介绍了Java生成随机姓名、性别和年龄的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-10-01
  • SQLMAP结合Meterpreter实现注入渗透返回shell

    sqlmap 是一个自动SQL 射入工具。它是可胜任执行一个广泛的数据库管理系统后端指印, 检索遥远的DBMS 数据库等,下面我们来看一个学习例子。 自己搭建一个PHP+MYSQ...2016-11-25