文章来源:http://www.cnblogs.com/hello-tl/p/7592974.html

<?php
/**
* 处理图片类
* 1.添加文字水印
* 2.添加图片水印
* 3.压缩图片
*/
class TL_Image{
private $image;//内存中的图片
private $info;//图片的基本信息
/**
* 打开一张图片,读取到内存
* @param [type] $src [description] 图片路径
*/
public function __construct($src){
$info = getimagesize($src);
$this->info = array(
'width' => $info[0],
'height' => $info[1],
'type' => image_type_to_extension($info['2'],false),
'mime' => $info['mime'],
);
$fun = "imagecreatefrom{$this->info['type']}";
$this->image = $fun($src);
}
/**
* 操作图片(压缩)
* @param [type] $width [description] 宽
* @param [type] $height [description] 高
* @return [type] [description]
*/
public function thumb($width,$height){
$image_thumb = imagecreatetruecolor($width,$height);
imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info['width'], $this->info['height']);
imagedestroy($this->image);
$this->image = $image_thumb;
}
/**
* 操作图片(添加文字水印)
* [fontMark description]
* @param [type] $content [description] 设置文字
* @param [type] $font_url [description] 字体文件路径
* @param [type] $size [description] 字体大小
* @param [type] $color [description] 字体颜色 []
* @param [type] $local [description] 位置 []
* @param [type] $angle [description] 旋转
* @return [type] [description]
*/
public function fontMark($content,$font_url,$size,$color,$local,$angle){
$col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);
imagettftext($this->image, $size, $angle, $local['x'], $local['y'], $col, $font_url, $content);
}
/**
* 操作图片(添加图片水印)
* @param [type] $source [description] 水印图片路径
* @param [type] $local [description] 位置 []
* @param [type] $alpha [description] 透明
* @return [type] [description]
*/
public function imageMark($source,$local,$alpha){
$info2 = getimagesize($source);
$type2 = image_type_to_extension($info2[2],false);
$fun2 = "imagecreatefrom{$type2}";
$water = $fun2($source);
imagecopymerge($this->image, $water, $local['x'], $local['y'], 0, 0, $info2[0], $info2[1], $alpha);
imagedestroy($water);
}
/**
* 浏览器输出图片
*/
public function show(){
header("Content-Type:" . $this->info['mime']);
$funs = "image{$this->info['type']}";
$funs($this->image);
}
/**
* 保存图片
* @param [type] $newname [description] 保存之后的名字
* @return [type] [description]
*/
public function save($srcs){
$funs = "image{$this->info['type']}";
$funs($this->image,$srcs);
//move_uploaded_file($this->image, $srcs);
}
/**
* 销毁图片
*/
public function __destruct(){
imagedestroy($this->image);
}
}

文章来源:http://www.cnblogs.com/hello-tl/p/7592974.html

最新文章

  1. javascript判断元素存在和判断元素存在于实时的dom中的方法
  2. InnoDB Spin rounds per wait在&gt;32位机器上可能为负
  3. INNO 补丁制作技术, 打开 INNO 补丁制作方法的第一页
  4. java版复利计算器升级
  5. 3种用组策略将域帐号加入本地管理员组的方法_jinifly_新浪博客
  6. 通过SEP屏蔽共享文件夹
  7. unity, 非public变量需要加[SerializeField]才能序列化
  8. PhoneGap开发手机程序入门教程
  9. 分布式存储Memcache替代Session方案
  10. js柯里化的一个应用
  11. [Unity 设计模式]桥接模式(BridgePattern)
  12. Alpha冲刺No.4
  13. 【集训第四天&#183;继续刷题】之 lgh怒刚ypj
  14. RocketMQ4.4.0新特性分享
  15. 第39章 引用令牌 - Identity Server 4 中文文档(v1.0.0)
  16. renren-security旧版本 分模块 的模块之间关系浅析
  17. vim 撤销 回退操作
  18. P2073 送花
  19. 关于send message 函数
  20. Linux 基础教程 34-软件包管理-RPM

热门文章

  1. 【插件开发】—— 10 JFace开发详解
  2. springboot(十)SpringBoot消息中间件RabbitMQ
  3. C# DateTime.Now 详解
  4. Android项目通过Android Debug Database实时查看本地Sqlite数据库内容
  5. 《Google软件测试之道》心得笔记1
  6. BZOJ2006 超级钢琴
  7. Effective Java读书笔记完结啦
  8. SpringBoot_自定义配置属性
  9. U9249 【模板】BSGS
  10. esp8266 串口通讯