您好,登錄后才能下訂單哦!
<?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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。