<小田吃餃子> PHP:GD庫 圖片浮水印處理

來源:互聯網
上載者:User

標籤:color   rip   基本   處理   height   function   from   source   大小   

<?php/** * 處理圖片類 * 1.添加文字浮水印 * 2.添加圖片浮水印 * 3.壓縮圖片 */class TL_Image{private $image;//記憶體中的圖片private $info;//圖片的基本資料/** * 開啟一張圖片,讀取到記憶體 * @param [type] $src [description] 圖片路徑 */public function __construct($src){$info = getimagesize($src);$this->info = array(‘width‘ => $info[0],‘height‘ => $info[1],‘type‘ => image_type_to_extension($info[‘2‘],false),‘mime‘ => $info[‘mime‘],);$fun = "imagecreatefrom{$this->info[‘type‘]}";$this->image = $fun($src);}/** * 操作圖片(壓縮) * @param  [type] $width  [description] 寬 * @param  [type] $height [description] 高 * @return [type]         [description] */public function thumb($width,$height){$image_thumb = imagecreatetruecolor($width,$height);imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[‘width‘], $this->info[‘height‘]);imagedestroy($this->image);$this->image = $image_thumb;}/** * 操作圖片(添加文字浮水印) * [fontMark description] * @param  [type] $content  [description] 設定文字 * @param  [type] $font_url [description] 字型檔路徑 * @param  [type] $size     [description] 字型大小 * @param  [type] $color    [description] 字型顏色 [] * @param  [type] $local    [description] 位置 [] * @param  [type] $angle    [description] 旋轉 * @return [type]           [description] */public function fontMark($content,$font_url,$size,$color,$local,$angle){$col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);imagettftext($this->image, $size, $angle, $local[‘x‘], $local[‘y‘], $col, $font_url, $content);}/** * 操作圖片(添加圖片浮水印) * @param  [type] $source [description] 浮水印圖片路徑 * @param  [type] $local  [description] 位置 [] * @param  [type] $alpha  [description] 透明 * @return [type]         [description]  */public function imageMark($source,$local,$alpha){$info2 = getimagesize($source);$type2 = image_type_to_extension($info2[2],false);$fun2 = "imagecreatefrom{$type2}";$water = $fun2($source);imagecopymerge($this->image, $water,  $local[‘x‘],  $local[‘y‘], 0, 0, $info2[0], $info2[1], $alpha);imagedestroy($water);}/** * 瀏覽器輸出圖片 */public function show(){header("Content-Type:" . $this->info[‘mime‘]);$funs = "image{$this->info[‘type‘]}";$funs($this->image);}/** * 儲存圖片 * @param  [type] $newname [description] 儲存之後的名字 * @return [type]         [description] */public function save($srcs){$funs = "image{$this->info[‘type‘]}";$funs($this->image,$srcs);//move_uploaded_file($this->image, $srcs);}/** * 銷毀圖片 */public function __destruct(){imagedestroy($this->image);}}

  

<小田吃餃子> PHP:GD庫 圖片浮水印處理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.