麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > PHP > 正文

摘自織夢CMS中的圖片處理類

2024-05-04 23:38:39
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了摘自織夢CMS中的圖片處理類,通過面向對象的方式較為詳細的實現了php針對圖片的縮略圖生成及水印添加等操作技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了摘自織夢CMS中的圖片處理類。分享給大家供大家參考。具體如下:

 

 
  1. <?php if(!defined('DEDEINC')) exit('dedecms'); 
  2. /** 
  3. * 圖像處理類 
  4. * 
  5. * @version $Id: image.class.php 1 18:10 2010年7月5日Z tianya $ 
  6. * @package DedeCMS.Libraries 
  7. * @copyright Copyright (c) 2007 - 2010, DesDev, Inc. 
  8. * @license http://help.dedecms.com/usersguide/license.html 
  9. * @link http://www.dedecms.com 
  10. */ 
  11. class image 
  12. var $attachinfo
  13. var $targetfile//圖片路徑 
  14. var $imagecreatefromfunc
  15. var $imagefunc
  16. var $attach
  17. var $animatedgif
  18. var $watermarkquality
  19. var $watermarktext
  20. var $thumbstatus
  21. var $watermarkstatus
  22. // 析構函數,兼容PHP4 
  23. function image($targetfile$cfg_thumb$cfg_watermarktext$photo_waterpos$photo_diaphaneity$photo_wheight$photo_wwidth$cfg_watermarktype$photo_marktrans,$trueMarkimg$attach = array()) 
  24. $this->__construct($targetfile$cfg_thumb$cfg_watermarktext$photo_waterpos$photo_diaphaneity$photo_wheight$photo_wwidth$cfg_watermarktype$photo_marktrans,$trueMarkimg$attach); 
  25. // 析構函數 
  26. function __construct($targetfile$cfg_thumb$cfg_watermarktext$photo_waterpos$photo_diaphaneity$photo_wheight$photo_wwidth$cfg_watermarktype$photo_marktrans,$trueMarkimg$attach = array()) 
  27. $this->thumbstatus = $cfg_thumb
  28. $this->watermarktext = $cfg_watermarktext
  29. $this->watermarkstatus = $photo_waterpos
  30. $this->watermarkquality = $photo_marktrans
  31. $this->watermarkminwidth = $photo_wwidth
  32. $this->watermarkminheight = $photo_wheight
  33. $this->watermarktype = $cfg_watermarktype
  34. $this->watermarktrans = $photo_diaphaneity
  35. $this->animatedgif = 0; 
  36. $this->targetfile = $targetfile
  37. $this->attachinfo = @getimagesize($targetfile); 
  38. $this->attach = $attach
  39. switch($this->attachinfo['mime']) 
  40. case 'image/jpeg'
  41. $this->imagecreatefromfunc = function_exists('imagecreatefromjpeg') ? 'imagecreatefromjpeg' : ''
  42. $this->imagefunc = function_exists('imagejpeg') ? 'imagejpeg' : ''
  43. break
  44. case 'image/gif'
  45. $this->imagecreatefromfunc = function_exists('imagecreatefromgif') ? 'imagecreatefromgif' : ''
  46. $this->imagefunc = function_exists('imagegif') ? 'imagegif' : ''
  47. break
  48. case 'image/png'
  49. $this->imagecreatefromfunc = function_exists('imagecreatefrompng') ? 'imagecreatefrompng' : ''
  50. $this->imagefunc = function_exists('imagepng') ? 'imagepng' : ''
  51. break
  52. }//為空則匹配類型的函數不存在 
  53. $this->attach['size'] = emptyempty($this->attach['size']) ? @filesize($targetfile) : $this->attach['size']; 
  54. if($this->attachinfo['mime'] == 'image/gif'
  55. $fp = fopen($targetfile'rb'); 
  56. $targetfilecontent = fread($fp$this->attach['size']); 
  57. fclose($fp); 
  58. $this->animatedgif = strpos($targetfilecontent'NETSCAPE2.0') === false ? 0 : 1; 
  59. /** 
  60. * 生成縮略圖 
  61. * 
  62. * @access public 
  63. * @param int $thumbwidth 圖片寬度 
  64. * @param int $thumbheight 圖片高度 
  65. * @param int $preview 是否預覽 
  66. * @return void 
  67. */ 
  68. function thumb($thumbwidth$thumbheight$preview = 0) 
  69. $this->thumb_gd($thumbwidth$thumbheight$preview); 
  70.  
  71. if($this->thumbstatus == 2 && $this->watermarkstatus) 
  72. $this->image($this->targetfile, $this->attach); 
  73. $this->attach['size'] = filesize($this->targetfile); 
  74. /** 
  75. * 圖片水印 
  76. * 
  77. * @access public 
  78. * @param int $preview 是否預覽 
  79. * @return void 
  80. */ 
  81. function watermark($preview = 0) 
  82. if($this->watermarkminwidth && $this->attachinfo[0] <= $this->watermarkminwidth && $this->watermarkminheight && $this->attachinfo[1] <= $this->watermarkminheight) 
  83. return ; 
  84. $this->watermark_gd($preview); 
  85. /** 
  86. * 使用gd生成縮略圖 
  87. * 
  88. * @access public 
  89. * @param int $thumbwidth 圖片寬度 
  90. * @param int $thumbheight 圖片高度 
  91. * @param int $preview 是否預覽 
  92. * @return void 
  93. */ 
  94. function thumb_gd($thumbwidth$thumbheight$preview = 0) 
  95. if($this->thumbstatus && function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg')) 
  96. $imagecreatefromfunc = $this->imagecreatefromfunc; 
  97. $imagefunc = $this->thumbstatus == 1 ? 'imagejpeg' : $this->imagefunc; 
  98. list($imagewidth$imageheight) = $this->attachinfo; 
  99. if(!$this->animatedgif && ($imagewidth >= $thumbwidth || $imageheight >= $thumbheight)) 
  100. $attach_photo = $imagecreatefromfunc($this->targetfile); 
  101. $x_ratio = $thumbwidth / $imagewidth
  102. $y_ratio = $thumbheight / $imageheight
  103. if(($x_ratio * $imageheight) < $thumbheight
  104. $thumb['height'] = ceil($x_ratio * $imageheight); 
  105. $thumb['width'] = $thumbwidth
  106. else 
  107. $thumb['width'] = ceil($y_ratio * $imagewidth); 
  108. $thumb['height'] = $thumbheight
  109. $targetfile = !$preview ? ($this->thumbstatus == 1 ? $this->targetfile.'.thumb.jpg' : $this->targetfile) : './watermark_tmp.jpg'
  110. $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']); 
  111. imagecopyresampled($thumb_photo$attach_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $imagewidth$imageheight); 
  112. if($this->attachinfo['mime'] == 'image/jpeg'
  113. $imagefunc($thumb_photo$targetfile, 100); 
  114. else 
  115. $imagefunc($thumb_photo$targetfile); 
  116. $this->attach['thumb'] = $this->thumbstatus == 1 ? 1 : 0; 
  117. /** 
  118. * 使用gd進行水印 
  119. * 
  120. * @access public 
  121. * @param int $preview 是否預覽 
  122. * @return void 
  123. */ 
  124. function watermark_gd($preview = 0) 
  125. if($this->watermarkstatus && function_exists('imagecopy') && function_exists('imagealphablending') && function_exists('imagecopymerge')) 
  126. $imagecreatefunc = $this->imagecreatefromfunc; 
  127. $imagefunc = $this->imagefunc; 
  128. list($imagewidth$imageheight) = $this->attachinfo; 
  129. if($this->watermarktype < 2) 
  130. $watermark_file = $this->watermarktype == 1 ? DEDEDATA.'/mark/mark.png' : DEDEDATA.'/mark/mark.gif'
  131. $watermarkinfo = @getimagesize($watermark_file); 
  132. $watermark_logo = $this->watermarktype == 1 ? @imagecreatefrompng($watermark_file) : @imagecreatefromgif($watermark_file); 
  133. if(!$watermark_logo
  134. return ; 
  135. list($logowidth$logoheight) = $watermarkinfo
  136. else 
  137. $box = @imagettfbbox($this->watermarktext['size'], $this->watermarktext['angle'], $this->watermarktext['fontpath'],$this->watermarktext['text']); 
  138. $logowidth = max($box[2], $box[4]) - min($box[0], $box[6]); 
  139. $logoheight = max($box[1], $box[3]) - min($box[5], $box[7]); 
  140. $ax = min($box[0], $box[6]) * -1; 
  141. $ay = min($box[5], $box[7]) * -1; 
  142. $wmwidth = $imagewidth - $logowidth
  143. $wmheight = $imageheight - $logoheight
  144. if(($this->watermarktype < 2 && is_readable($watermark_file) || $this->watermarktype == 2) && $wmwidth > 10 && $wmheight > 10 && !$this->animatedgif) 
  145. switch($this->watermarkstatus) 
  146. case 1: 
  147.  
  148. $x = +5; 
  149. $y = +5; 
  150. break
  151. case 2: 
  152. $x = ($imagewidth - $logowidth) / 2; 
  153. $y = +5; 
  154. break
  155. case 3: 
  156. $x = $imagewidth - $logowidth - 5; 
  157. $y = +5; 
  158. break
  159. case 4: 
  160. $x = +5; 
  161. $y = ($imageheight - $logoheight) / 2; 
  162. break
  163. case 5: 
  164. $x = ($imagewidth - $logowidth) / 2; 
  165. $y = ($imageheight - $logoheight) / 2; 
  166. break
  167. case 6: 
  168. $x = $imagewidth - $logowidth - 5; 
  169. $y = ($imageheight - $logoheight) / 2; 
  170. break
  171. case 7: 
  172. $x = +5; 
  173. $y = $imageheight - $logoheight - 5; 
  174. break
  175. case 8: 
  176. $x = ($imagewidth - $logowidth) / 2; 
  177. $y = $imageheight - $logoheight - 5; 
  178. break
  179. case 9: 
  180. $x = $imagewidth - $logowidth - 5; 
  181. $y = $imageheight - $logoheight -5; 
  182. break
  183. $dst_photo = @imagecreatetruecolor($imagewidth$imageheight); 
  184. $target_photo = $imagecreatefunc($this->targetfile); 
  185. imagecopy($dst_photo$target_photo, 0, 0, 0, 0, $imagewidth$imageheight); 
  186. if($this->watermarktype == 1) 
  187. imagecopy($dst_photo$watermark_logo$x$y, 0, 0, $logowidth$logoheight); 
  188. elseif($this->watermarktype == 2) 
  189. if(($this->watermarktext['shadowx'] || $this->watermarktext['shadowy']) && $this->watermarktext['shadowcolor']) 
  190. $shadowcolorrgb = explode(','$this->watermarktext['shadowcolor']); 
  191. $shadowcolor = imagecolorallocate($dst_photo$shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]); 
  192. imagettftext($dst_photo$this->watermarktext['size'], $this->watermarktext['angle'], 
  193. $x + $ax + $this->watermarktext['shadowx'], $y + $ay + $this->watermarktext['shadowy'], $shadowcolor
  194. $this->watermarktext['fontpath'], $this->watermarktext['text']); 
  195. $colorrgb = explode(','$this->watermarktext['color']); 
  196. $color = imagecolorallocate($dst_photo$colorrgb[0], $colorrgb[1], $colorrgb[2]); 
  197. imagettftext($dst_photo$this->watermarktext['size'], $this->watermarktext['angle'], 
  198. $x + $ax$y + $ay$color$this->watermarktext['fontpath'], $this->watermarktext['text']); 
  199. else 
  200. imagealphablending($watermark_logo, true); 
  201. imagecopymerge($dst_photo$watermark_logo$x$y, 0, 0, $logowidth$logoheight$this->watermarktrans); 
  202. $targetfile = !$preview ? $this->targetfile : './watermark_tmp.jpg'
  203. if($this->attachinfo['mime'] == 'image/jpeg'
  204. $imagefunc($dst_photo$targetfile$this->watermarkquality); 
  205. else 
  206. $imagefunc($dst_photo$targetfile); 
  207. $this->attach['size'] = filesize($this->targetfile); 
  208. }//End Class 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩视频在线一区二区三区 | 天海翼四虎精品正在播放 | 日韩视频在线一区二区三区 | 依依成人精品视频 | 中文字幕精品一二三四五六七八 | 国产精品久久久久久久av三级 | 久久久久一本一区二区青青蜜月 | 日本成人午夜 | 免费黄色小网站 | 国产精品视频一区二区三区综合 | 韩国精品一区二区三区四区五区 | 成人三级黄色片 | 久久久久女人精品毛片九一 | 中国女警察一级毛片视频 | cosplay裸体福利写真 | 91av日韩 | 国产99视频精品免视看9 | 欧美激情综合在线 | 国产精品久久久久久影院8一贰佰 | 欧美电影在线观看 | 久久亚洲精品国产一区 | 精品国产91一区二区三区 | 成年人在线视频免费 | 小雪奶水翁胀公吸小说最新章节 | 欧美a视频在线观看 | 久久99精品国产99久久6男男 | 久久99国产伦子精品免费 | 欧美一级高潮片免费的 | 国产一级毛片高清视频完整版 | 新久草在线视频 | 国产中文99视频在线观看 | 欧美a在线看 | 全黄毛片| 4p嗯啊巨肉寝室调教男男视频 | 日韩在线激情 | 黄色免费电影网址 | 一级一级一级一级毛片 | 色蜜桃av | 91精彩视频| 亚洲射逼| 精品久久久久久久久久久久久久 |