无为清净楼资源网 Design By www.qnjia.com

php对图片文件的操作主要是利用GD库扩展。当我们频繁利用php对图片进行操作时,会自然封装很多函数,否则会写太多重复的代码。当有很多对图片的相关函数的时候,我们可以考虑将这些函数也整理一下,因而就有了封装成类的想法。

操作图片主要历经四个步骤

1、打开图片
2、操作图片
3、输出图片
4、销毁图片

1,3,4三个步骤每次都要写,每次又都差不多。真正需要变通的只有操作图片的这一步骤了。操作图片又往往通过1或多个主要的GD函数来完成。

<"imagecreatefrom{$this->type}";
  $this->image=$fun($src);
 }
 /**
  * 文字水印
  * @param [type] $font  字体
  * @param [type] $content 内容
  * @param [type] $size  文字大小
  * @param [type] $col  文字颜色(四元数组)
  * @param array $location 位置 
  * @param integer $angle 倾斜角度
  * @return [type]   
  */
 public function fontMark($font,$content,$size,$col,$location,$angle=0){
  $col=imagecolorallocatealpha($this->image, $col['0'], $col['1'], $col['2'],$col['3']);

  imagettftext($this->image, $size, $angle, $location['0'], $location['1'], $col,$font,$content);
 }
 
 /**
  * 图片水印
  * @param [type] $imageMark 水印图片地址
  * @param [type] $dst  水印图片在原图片中的位置
  * @param [type] $pct  透明度
  * @return [type]   
  */
 public function imageMark($imageMark,$dst,$pct){
  $info2=getimagesize($imageMark);
  $type=image_type_to_extension($info2['2'],false);
  $func2="imagecreatefrom".$type;
  $water=$func2($imageMark);

  imagecopymerge($this->image, $water, $dst[0], $dst[1], 0, 0, $info2['0'], $info2['1'], $pct);
  imagedestroy($water);

 }
 /**
  * 压缩图片
  * @param [type] $thumbSize 压缩图片大小
  * @return [type]   [description]
  */
 public function thumb($thumbSize){
  $imageThumb=imagecreatetruecolor($thumbSize[0], $thumbSize[1]);
  
  imagecopyresampled($imageThumb, $this->image, 0, 0, 0, 0, $thumbSize[0], $thumbSize[1], $this->info['0'], $this->info['1']);
  imagedestroy($this->image);
  $this->image=$imageThumb;
 }
 /**
 * 裁剪图片
  * @param [type] $cutSize 裁剪大小
  * @param [type] $location 裁剪位置
  * @return [type]   [description]
  */
  public function cut($cutSize,$location){
   $imageCut=imagecreatetruecolor($cutSize[0],$cutSize[1]);

   imagecopyresampled($imageCut, $this->image, 0, 0, $location[0], $location[1],$cutSize[0],$cutSize[1],$cutSize[0],$cutSize[1]);
   imagedestroy($this->image);
   $this->image=$imageCut;
  }
 /**
  * 展现图片
  * @return [type] [description]
  */
 public function show(){
  header("content-type:".$this->info['mime']);

  $funn="image".$this->type;

  $funn($this->image);
 }
 /**
  * 保存图片
 * @param [type] $newname 新图片名
 * @return [type]   [description]
 */
  public function save($newname){
   header("content-type:".$this->info['mime']);

   $funn="image".$this->type;

   $funn($this->image,$newname.'.'.$this->type);
  }
  public function __destruct(){
   imagedestroy($this->image);
  }

 }

 ?>

是不是这样操作就很简单了,如果还需要其他操作,只需要再往这个类里面添加就好啦~~希望大家可以熟练掌握。

标签:
php图片水印添加,php图片压缩,php图片剪切

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?