首页 / PHP / 图片添加文字水印和图片水印
图片添加文字水印和图片水印
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了图片添加文字水印和图片水印,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2055字,纯文字阅读大概需要3分钟。
内容图文
<?php /** * @desc 图片处理类 */ class Pic{ private $info; private $res; public $thumb_pic; public function __construct($picPath){ //获取图片信息 $this->info = getimagesize($picPath); //获取图片名 $this->info['type'] = image_type_to_extension($this->info[2],false); $funs = 'imagecreatefrom'.$this->info['type']; $this->res = $funs($picPath); } //缩略图 public function thumb($w=100,$h=100){ //创建图片资源 $image_thumb = imagecreatetruecolor($w,$h); imagecopyresampled($image_thumb,$this->res,0,0,0,0,$w,$h,$this->info[0],$this->info[1]); imagedestroy($this->res); $this->res = $image_thumb; } //展示 public function showPic(){ header('Content-type:'.$this->info['type']); $funs = 'image'.$this->info['type']; $funs($this->res); } //保存 public function savePic($newname){ $funs = 'image'.$this->info['type']; $funs($this->res,$newname.".".$this->info['type']); } //销毁图片 public function __destruct(){ imagedestroy($this->res); } /** * @desc 添加文字水印 * @param $content string 文字 * @param $fonturl string 字体路径 * @param $fontsize int 字体大小 * @param $fontcolor array 设置颜色和透明度 * @param $local array 水印坐标 * @param $fontangle int 字体旋转角度 */ public function fontMark($content,$fonturl,$fontsize,$fontcolor,$local,$fontangle){ $color = imagecolorallocatealpha($this->res,$fontcolor[0],$fontcolor[1],$fontcolor[2],$fontcolor[3]); imagettftext($this->res,$fontsize,$fontangel,$local['x'],$local['y'],$color,$fonturl,$content); } /** * @desc 添加图片水印 * @param $markPic string 水印图片 * @param $local array 图片坐标 * @param $alpha array 设置颜色和透明度 */ public function picMark($markPic,$local,$alpha){ $markInfo = getimagesize($markPic); $markType = image_type_to_extension($markInfo[2],false); $markFun = 'imagecreatefrom'.$markType; $markWater = $markFun($markPic); imagecopymerge($this->res,$markWater,$local['x'],$local['y'],0,0,$markInfo[0],$markInfo[1],$alpha); imagedestroy($markWater); } } $pic = new Pic('yibo_pic28.jpg'); $pic->picMark('logo3.png',array('x'=>50,'y'=>50),30); $pic->showPic();
以上就介绍了图片添加文字水印 和图片水印,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
内容总结
以上是互联网集市为您收集整理的图片添加文字水印和图片水印全部内容,希望文章能够帮你解决图片添加文字水印和图片水印所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。