圖片加水印縮略圖類_第1頁
圖片加水印縮略圖類_第2頁
圖片加水印縮略圖類_第3頁
圖片加水印縮略圖類_第4頁
圖片加水印縮略圖類_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、<?php/MyPic 圖片加水印, 生成縮略圖類/ 原始圖片$img1 = './image/test.jpg'/ 水印后的圖片$img2 = './image/test_new.jpg'/ 水印$water = './image/water.gif'$img = new image();/ 等比縮放$img->param($img1)->thumb('./image/test_0.jpg', 200,200,0);/ center center 裁剪$img->param($img1)->thum

2、b('./image/test_1.jpg', 200,200,1);/ top left 裁剪$img->param($img1)->thumb('./image/test_2.jpg', 200,200,2);/ 右下角添加水印$img->param($img1)->water($img2,$water,9);/* +-+* | Copyright (c) 2008-2009 Diqiye.Com All rights reserved.* +-+* | Info : 圖像處理類* +-+*/class image / 當前圖片 pr

3、otected $img; / 圖像types 對應表 protected $types = array( 1 => 'gif', 2 => 'jpg', 3 => 'png', 6 => 'bmp' ); / image public function _construct($img='') !$img && $this->param($img); / Info public function param($img) $this->img = $img; ret

4、urn $this; / imageInfo public function getImageInfo($img) $info = getimagesize($img); if(isset($this->types$info2) $info'ext' = $info'type' = $this->types$info2; else $info'ext' = $info'type' = 'jpg' $info'type' = 'jpg' && $info&#

5、39;type' = 'jpeg' $info'size' = filesize($img); return $info; / thumb(新圖地址, 寬, 高, 裁剪, 允許放大) public function thumb($filename,$new_w=160,$new_h=120,$cut=0,$big=0) / 獲取原圖信息 $info = $this->getImageInfo($this->img); if(!empty($info0) $old_w = $info0; $old_h = $info1; $type = $in

6、fo'type' $ext = $info'ext' unset($info); / 如果原圖比縮略圖小 并且不允許放大 if($old_w < $new_h && $old_h < $new_w && !$big) return false; / 裁剪圖片 if($cut = 0) / 等比列 $scale = min($new_w/$old_w, $new_h/$old_h); / 計算縮放比例 $width = (int)($old_w*$scale); / 縮略圖尺寸 $height = (int)($old_

7、h*$scale); $start_w = $start_h = 0; $end_w = $old_w; $end_h = $old_h; elseif($cut = 1) / center center 裁剪 $scale1 = round($new_w/$new_h,2); $scale2 = round($old_w/$old_h,2); if($scale1 > $scale2) $end_h = round($old_w/$scale1,2); $start_h = ($old_h-$end_h)/2; $start_w = 0; $end_w = $old_w; else $

8、end_w = round($old_h*$scale1,2); $start_w = ($old_w-$end_w)/2; $start_h = 0; $end_h = $old_h; $width = $new_w; $height= $new_h; elseif($cut = 2) / left top 裁剪 $scale1 = round($new_w/$new_h,2); $scale2 = round($old_w/$old_h,2); if($scale1 > $scale2) $end_h = round($old_w/$scale1,2); $end_w = $old_

9、w; else $end_w = round($old_h*$scale1,2); $end_h = $old_h; $start_w = 0; $start_h = 0; $width = $new_w; $height= $new_h; / 載入原圖 $createFun = 'ImageCreateFrom'.$type; $oldimg = $createFun($this->img); / 創(chuàng)建縮略圖 if($type!='gif' && function_exists('imagecreatetruecolor'

10、) $newimg = imagecreatetruecolor($width, $height); else $newimg = imagecreate($width, $height); / 復制圖片 if(function_exists("ImageCopyResampled") ImageCopyResampled($newimg, $oldimg, 0, 0, $start_w, $start_h, $width, $height, $end_w,$end_h); else ImageCopyResized($newimg, $oldimg, 0, 0, $sta

11、rt_w, $start_h, $width, $height, $end_w,$end_h); / 對jpeg圖形設置隔行掃描 $type = 'jpeg' && imageinterlace($newimg,1); / 生成圖片 $imageFun = 'image'.$type; !$imageFun($newimg,$filename) && die('保存失敗!檢查目錄是否存在并且可寫?'); ImageDestroy($newimg); ImageDestroy($oldimg); return $fi

12、lename; return false; / water(保存地址,水印圖片,水印位置,透明度) public function water($filename,$water,$pos=0,$pct=80) / 加載水印圖片 $info = $this->getImageInfo($water); if(!empty($info0) $water_w = $info0; $water_h = $info1; $type = $info'type' $fun = 'imagecreatefrom'.$type; $waterimg = $fun($wate

13、r); else return false; / 加載背景圖片 $info = $this->getImageInfo($this->img); if(!empty($info0) $old_w = $info0; $old_h = $info1; $type = $info'type' $fun = 'imagecreatefrom'.$type; $oldimg = $fun($this->img); else return false; / 剪切水印 $water_w >$old_w && $water_w = $o

14、ld_w; $water_h >$old_h && $water_h = $old_h; / 水印位置 switch($pos) case 0:/隨機 $posX = rand(0,($old_w - $water_w); $posY = rand(0,($old_h - $water_h); break; case 1:/1為頂端居左 $posX = 0; $posY = 0; break; case 2:/2為頂端居中 $posX = ($old_w - $water_w) / 2; $posY = 0; break; case 3:/3為頂端居右 $posX = $

15、old_w - $water_w; $posY = 0; break; case 4:/4為中部居左 $posX = 0; $posY = ($old_h - $water_h) / 2; break; case 5:/5為中部居中 $posX = ($old_w - $water_w) / 2; $posY = ($old_h - $water_h) / 2; break; case 6:/6為中部居右 $posX = $old_w - $water_w; $posY = ($old_h - $water_h) / 2; break; case 7:/7為底端居左 $posX = 0; $p

16、osY = $old_h - $water_h; break; case 8:/8為底端居中 $posX = ($old_w - $water_w) / 2; $posY = $old_h - $water_h; break; case 9:/9為底端居右 $posX = $old_w - $water_w; $posY = $old_h - $water_h; break; default: /隨機 $posX = rand(0,($old_w - $water_w); $posY = rand(0,($old_h - $water_h); break; / 設定圖像的混色模式 imagealphablending($oldimg, true); / 添加水印

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論