<?php namespace vendor\gd\xx; /** * GDImg is the model behind the p_w_picpath. * * //设定图片尺寸 * $width = 300; * $height = 150; * //图片一 * $src = '001.jpg'; * //$content = 'hello'; * //$font_url = 'arial.ttf'; * //$size = 20; * //$color = [255,255,255,20]; * //$local = ['x' => 20, 'y' => 30]; * //$angle = 10; * //图片二 * $source = "002.jpg"; * $local = ['x' => 0, 'y' => $height]; //图片位置 * $alpha = 100; //图片透明度 * * $p_w_picpath = new Image($src); * // TODO:以下宽高为配置的主面板显示宽高和图片一宽高 * $p_w_picpath->thumb($width, $height*2, $width, $height); //压缩图片 * //$p_w_picpath->fontMark($content, $font_url, $size, $color, $local, $angle); //合成文字水印 * $p_w_picpath->p_w_picpathMark($source, $local, $alpha, $width, $height); //合成图片水印并压缩 * $p_w_picpath->show(); //打印在浏览器 * //$p_w_picpath->save('abc'); //保存在硬盘中 * */ class GDImg extends Model{ /** * 内存中的图片 */ private $p_w_picpath; /** * 图片基本信息 */ public $info; /** * 打开一张图片,读取到内存中 * @ $src为图片本地路径 */ public function __construct($src){ $info = getp_w_picpathsize($src); $this->info = [ 'width' => $info[0], 'height' => $info[1], 'type' => p_w_picpath_type_to_extension($info['2'], false), 'mime' => $info['mime'], ]; $fun = "p_w_picpathcreatefrom{$this->info['type']}"; $this->p_w_picpath = $fun($src); } /** * 操作图片(压缩) * @ $width为面板宽度 * @ $height为面板高度 * @ $width3为图片一宽度 * @ $height2为图片一高度 */ public function thumb($width, $height, $width3, $height2){ $p_w_picpath_thumb = p_w_picpathcreatetruecolor($width, $height); p_w_picpathcopyresampled($p_w_picpath_thumb, $this->p_w_picpath, 0, 0, 0, 0, $width3, $height2, $this->info['width'], $this->info['height']); p_w_picpathdestroy($this->p_w_picpath); $this->p_w_picpath = $p_w_picpath_thumb; } /** * 操作图片(添加文字水印) * @ $content为文字内容 * @ $font_url为字体路径 * @ $size为字体大小 * @ $color为字体颜色 * @ $local为字体位置 */ public function fontMark($content, $font_url, $size, $color, $local, $angle){ $col = p_w_picpathcolorallocatealpha($this->p_w_picpath, $color[0], $color[1], $color[2], $color[3]); p_w_picpathttftext($this->p_w_picpath, $size, $angle, $local['x'], $local['y'], $col, $font_url, $content); } /** * 操作图片(添加图片水印) * @ $source为本地图片路径 * @ $local为图片位置 * @ $alpha为图片透明度 */ public function p_w_picpathMark($source, $local, $alpha, $width, $height){ $info2 = getp_w_picpathsize($source); $type2 = p_w_picpath_type_to_extension($info2[2], false); $fun2 = "p_w_picpathcreatefrom{$type2}"; $water = $fun2($source); //压解水印 $p_w_picpath_thumb2 = p_w_picpathcreatetruecolor($width, $height); p_w_picpathcopyresampled($p_w_picpath_thumb2, $water, 0, 0, 0, 0, $width, $height, $this->info['width'], $this->info['height']); p_w_picpathcopymerge($this->p_w_picpath, $p_w_picpath_thumb2, $local['x'], $local['y'], 0, 0, $info2[0], $info2[1], $alpha); p_w_picpathdestroy($water); } /** * 在浏览器中显示图片 */ public function show(){ header("Content-type:". $this->info['mime']); $fun = "p_w_picpath{$this->info['type']}"; $fun($this->p_w_picpath); } /** * 把图片保存在硬盘 * @ $newname为保存图片的名称 */ public function save($newname){ $fun = "p_w_picpath{$this->info['type']}"; $fun($this->p_w_picpath, $newname.'.'.$this->info['type']); } /** * 销毁图片 */ public function __destruct(){ p_w_picpathdestroy($this->p_w_picpath); } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。