PHP图像操作类
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP图像操作类,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1621字,纯文字阅读大概需要3分钟。
内容图文
基于已给出的各种图像操作方法,这里我总结出了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图像操作类所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。