PHP图像操作类
2015-07-30 14:28
267 查看
基于已给出的各种图像操作方法,这里我总结出了PHP图像操作的一个类,包括给图像添加文字水印、图像水印和压缩图片。读者可自行添加功能。
<?php class Image { private $info; private $type; private $iamge; /** * 打开图片,写入内存 * **/ public function __construct($src) { $this->info = getimagesize($src); $this->type = image_type_to_extension($this->info[2],false); $fun = "imagecreatefrom".$this->type; $this->image = $fun($src); } //缩略图 public function thumb($width, $height) { $image_thumb = imagecreatetruecolor($width, $height); imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[0], $this->info[1]); imagedestroy($this->image); $this->image = $image_thumb; } //文字水印 public function fontMark($content, $fontUrl, $size, $color, $locate=array('x'=>0,'y'=>0), $angle=0) { $color = imagecolorallocatealpha($this->image, $color[0], $color[1], $color[2], $color[3]); imagettftext($this->image, $size, $angle, $locate['x'], $locate['y'], $color, $fontUrl, $content); } //图片水印 public function imageMark($src,$locate,$alpha) { $info2 = getimagesize($src); $type2 = image_type_to_extension($info2[2],false); $fun2 = "imagecreatefrom".$type2; $water = $fun2($src); imagecopymerge($this->image, $water, $locate['x'], $locate['y'], 0, 0, $info2[0], $info2[1], $alpha); imagedestroy($water); } //在浏览器中显示 public function show() { header("Content-type:".$this->info['mime']); $fun = "image".$this->type; $fun($this->image); } //保存为文件 public function save($newname) { $fun = "image".$this->type; $fun($this->image, $newname.'.'.$this->type); } public function __destruct() { imagedestroy($this->image); } }
相关文章推荐
- PHP图片压缩
- PHP实现守护进程
- AbstractProcessor一些用法
- 15. PHP 全局变量 - 超全局变量
- 妙用AlertActivity的mAlertParams 和 mAlert
- STP生成树协议的分析总结
- PHP图片水印
- php 抽奖类的
- 14. PHP 数组排序
- php中在一个php文件调用另一个php的函数,保存登录时保存的用户id
- 13. PHP 数组
- php给图片添加文字水印
- PHP给图片加文字水印
- 使用阿里云集成包快速搭建LAMP+FTP教程
- PHP使用纯真IP数据库
- win2008R2 FTP 相关 200 227 550
- php-共享内存以及利用共享内存实现消息队列
- PHP利用Gearman来处理并行多进程问题
- thinkphp 构建子查询
- Serv-U FTP文件服务器端口映射