목차
摘自织梦CMS中的图片处理类,摘自织梦cms图片
php教程 php手册 摘自织梦CMS中的图片处理类,摘自织梦cms图片

摘自织梦CMS中的图片处理类,摘自织梦cms图片

Jun 13, 2016 am 08:56 AM
cms 이미지 처리

摘自织梦CMS中的图片处理类,摘自织梦cms图片

本文实例讲述了摘自织梦CMS中的图片处理类。分享给大家供大家参考。具体如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

<&#63;php if(!defined('DEDEINC')) exit('dedecms');

/**

 * 图像处理类

 *

 * @version  $Id: image.class.php 1 18:10 2010年7月5日Z tianya $

 * @package  DedeCMS.Libraries

 * @copyright  Copyright (c) 2007 - 2010, DesDev, Inc.

 * @license  http://help.dedecms.com/usersguide/license.html

 * @link   http://www.dedecms.com

 */

class image

{

 var $attachinfo;

 var $targetfile; //图片路径

 var $imagecreatefromfunc;

 var $imagefunc;

 var $attach;

 var $animatedgif;

 var $watermarkquality;

 var $watermarktext;

 var $thumbstatus;

 var $watermarkstatus;

 // 析构函数,兼容PHP4

 function image($targetfile, $cfg_thumb, $cfg_watermarktext, $photo_waterpos, $photo_diaphaneity, $photo_wheight, $photo_wwidth, $cfg_watermarktype, $photo_marktrans,$trueMarkimg, $attach = array())

 {

  $this->__construct($targetfile, $cfg_thumb, $cfg_watermarktext, $photo_waterpos, $photo_diaphaneity, $photo_wheight, $photo_wwidth, $cfg_watermarktype, $photo_marktrans,$trueMarkimg, $attach);

 }

 // 析构函数

 function __construct($targetfile, $cfg_thumb, $cfg_watermarktext, $photo_waterpos, $photo_diaphaneity, $photo_wheight, $photo_wwidth, $cfg_watermarktype, $photo_marktrans,$trueMarkimg, $attach = array())

 {

  $this->thumbstatus = $cfg_thumb;

  $this->watermarktext = $cfg_watermarktext;

  $this->watermarkstatus = $photo_waterpos;

  $this->watermarkquality = $photo_marktrans;

  $this->watermarkminwidth = $photo_wwidth;

  $this->watermarkminheight = $photo_wheight;

  $this->watermarktype = $cfg_watermarktype;

  $this->watermarktrans = $photo_diaphaneity;

  $this->animatedgif = 0;

  $this->targetfile = $targetfile;

  $this->attachinfo = @getimagesize($targetfile);

  $this->attach = $attach;

  switch($this->attachinfo['mime'])

  {

   case 'image/jpeg':

    $this->imagecreatefromfunc = function_exists('imagecreatefromjpeg') &#63; 'imagecreatefromjpeg' : '';

    $this->imagefunc = function_exists('imagejpeg') &#63; 'imagejpeg' : '';

    break;

   case 'image/gif':

    $this->imagecreatefromfunc = function_exists('imagecreatefromgif') &#63; 'imagecreatefromgif' : '';

    $this->imagefunc = function_exists('imagegif') &#63; 'imagegif' : '';

    break;

   case 'image/png':

    $this->imagecreatefromfunc = function_exists('imagecreatefrompng') &#63; 'imagecreatefrompng' : '';

    $this->imagefunc = function_exists('imagepng') &#63; 'imagepng' : '';

    break;

  }//为空则匹配类型的函数不存在

  $this->attach['size'] = empty($this->attach['size']) &#63; @filesize($targetfile) : $this->attach['size'];

  if($this->attachinfo['mime'] == 'image/gif')

  {

   $fp = fopen($targetfile, 'rb');

   $targetfilecontent = fread($fp, $this->attach['size']);

   fclose($fp);

   $this->animatedgif = strpos($targetfilecontent, 'NETSCAPE2.0') === false &#63; 0 : 1;

  }

 }

 /**

  * 生成缩略图

  *

  * @access public

  * @param  int $thumbwidth 图片宽度

  * @param  int $thumbheight 图片高度

  * @param  int $preview 是否预览

  * @return void

  */

 function thumb($thumbwidth, $thumbheight, $preview = 0)

 {

  $this->thumb_gd($thumbwidth, $thumbheight, $preview);

  

  if($this->thumbstatus == 2 && $this->watermarkstatus)

  {

   $this->image($this->targetfile, $this->attach);

   $this->attach['size'] = filesize($this->targetfile);

  }

 }

 /**

  * 图片水印

  *

  * @access public

  * @param  int $preview 是否预览

  * @return void

  */

 function watermark($preview = 0)

 {

  if($this->watermarkminwidth && $this->attachinfo[0] <= $this->watermarkminwidth && $this->watermarkminheight && $this->attachinfo[1] <= $this->watermarkminheight)

  {

   return ;

  }

  $this->watermark_gd($preview);

 }

 /**

  * 使用gd生成缩略图

  *

  * @access public

  * @param  int $thumbwidth 图片宽度

  * @param  int $thumbheight 图片高度

  * @param  int $preview 是否预览

  * @return void

  */

 function thumb_gd($thumbwidth, $thumbheight, $preview = 0)

 {

  if($this->thumbstatus && function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled') && function_exists('imagejpeg'))

  {

   $imagecreatefromfunc = $this->imagecreatefromfunc;

   $imagefunc = $this->thumbstatus == 1 &#63; 'imagejpeg' : $this->imagefunc;

   list($imagewidth, $imageheight) = $this->attachinfo;

   if(!$this->animatedgif && ($imagewidth >= $thumbwidth || $imageheight >= $thumbheight))

   {

    $attach_photo = $imagecreatefromfunc($this->targetfile);

    $x_ratio = $thumbwidth / $imagewidth;

    $y_ratio = $thumbheight / $imageheight;

    if(($x_ratio * $imageheight) < $thumbheight)

    {

     $thumb['height'] = ceil($x_ratio * $imageheight);

     $thumb['width'] = $thumbwidth;

    }

    else

    {

     $thumb['width'] = ceil($y_ratio * $imagewidth);

     $thumb['height'] = $thumbheight;

    }

    $targetfile = !$preview &#63; ($this->thumbstatus == 1 &#63; $this->targetfile.'.thumb.jpg' : $this->targetfile) : './watermark_tmp.jpg';

    $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']);

    imagecopyresampled($thumb_photo, $attach_photo, 0, 0, 0, 0, $thumb['width'], $thumb['height'], $imagewidth, $imageheight);

    if($this->attachinfo['mime'] == 'image/jpeg')

    {

     $imagefunc($thumb_photo, $targetfile, 100);

    }

    else

    {

     $imagefunc($thumb_photo, $targetfile);

    }

    $this->attach['thumb'] = $this->thumbstatus == 1 &#63; 1 : 0;

   }

  }

 }

 /**

  * 使用gd进行水印

  *

  * @access public

  * @param  int $preview 是否预览

  * @return void

  */

 function watermark_gd($preview = 0)

 {

  if($this->watermarkstatus && function_exists('imagecopy') && function_exists('imagealphablending') && function_exists('imagecopymerge'))

  {

   $imagecreatefunc = $this->imagecreatefromfunc;

   $imagefunc = $this->imagefunc;

   list($imagewidth, $imageheight) = $this->attachinfo;

   if($this->watermarktype < 2)

   {

    $watermark_file = $this->watermarktype == 1 &#63; DEDEDATA.'/mark/mark.png' : DEDEDATA.'/mark/mark.gif';

    $watermarkinfo = @getimagesize($watermark_file);

    $watermark_logo = $this->watermarktype == 1 &#63; @imagecreatefrompng($watermark_file) : @imagecreatefromgif($watermark_file);

    if(!$watermark_logo)

    {

     return ;

    }

    list($logowidth, $logoheight) = $watermarkinfo;

   }

   else

   {

    $box = @imagettfbbox($this->watermarktext['size'], $this->watermarktext['angle'], $this->watermarktext['fontpath'],$this->watermarktext['text']);

    $logowidth = max($box[2], $box[4]) - min($box[0], $box[6]);

    $logoheight = max($box[1], $box[3]) - min($box[5], $box[7]);

    $ax = min($box[0], $box[6]) * -1;

    $ay = min($box[5], $box[7]) * -1;

   }

   $wmwidth = $imagewidth - $logowidth;

   $wmheight = $imageheight - $logoheight;

   if(($this->watermarktype < 2 && is_readable($watermark_file) || $this->watermarktype == 2) && $wmwidth > 10 && $wmheight > 10 && !$this->animatedgif)

   {

    switch($this->watermarkstatus)

    {

     case 1:

  

      $x = +5;

      $y = +5;

      break;

     case 2:

      $x = ($imagewidth - $logowidth) / 2;

      $y = +5;

      break;

     case 3:

      $x = $imagewidth - $logowidth - 5;

      $y = +5;

      break;

     case 4:

      $x = +5;

      $y = ($imageheight - $logoheight) / 2;

      break;

     case 5:

      $x = ($imagewidth - $logowidth) / 2;

      $y = ($imageheight - $logoheight) / 2;

      break;

     case 6:

      $x = $imagewidth - $logowidth - 5;

      $y = ($imageheight - $logoheight) / 2;

      break;

     case 7:

      $x = +5;

      $y = $imageheight - $logoheight - 5;

      break;

     case 8:

      $x = ($imagewidth - $logowidth) / 2;

      $y = $imageheight - $logoheight - 5;

      break;

     case 9:

      $x = $imagewidth - $logowidth - 5;

      $y = $imageheight - $logoheight -5;

      break;

    }

    $dst_photo = @imagecreatetruecolor($imagewidth, $imageheight);

    $target_photo = $imagecreatefunc($this->targetfile);

    imagecopy($dst_photo, $target_photo, 0, 0, 0, 0, $imagewidth, $imageheight);

    if($this->watermarktype == 1)

    {

     imagecopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logowidth, $logoheight);

    }

    elseif($this->watermarktype == 2)

    {

     if(($this->watermarktext['shadowx'] || $this->watermarktext['shadowy']) && $this->watermarktext['shadowcolor'])

     {

      $shadowcolorrgb = explode(',', $this->watermarktext['shadowcolor']);

      $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);

      imagettftext($dst_photo, $this->watermarktext['size'], $this->watermarktext['angle'],

      $x + $ax + $this->watermarktext['shadowx'], $y + $ay + $this->watermarktext['shadowy'], $shadowcolor,

      $this->watermarktext['fontpath'], $this->watermarktext['text']);

     }

     $colorrgb = explode(',', $this->watermarktext['color']);

     $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);

     imagettftext($dst_photo, $this->watermarktext['size'], $this->watermarktext['angle'],

     $x + $ax, $y + $ay, $color, $this->watermarktext['fontpath'], $this->watermarktext['text']);

    }

    else

    {

     imagealphablending($watermark_logo, true);

     imagecopymerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logowidth, $logoheight, $this->watermarktrans);

    }

    $targetfile = !$preview &#63; $this->targetfile : './watermark_tmp.jpg';

    if($this->attachinfo['mime'] == 'image/jpeg')

    {

     $imagefunc($dst_photo, $targetfile, $this->watermarkquality);

    }

    else

    {

     $imagefunc($dst_photo, $targetfile);

    }

    $this->attach['size'] = filesize($this->targetfile);

   }

  }

 }

}//End Class

로그인 후 복사

希望本文所述对大家的php程序设计有所帮助。

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Laravel을 사용하여 이미지 처리 기능을 구현하는 방법 Laravel을 사용하여 이미지 처리 기능을 구현하는 방법 Nov 04, 2023 pm 12:46 PM

Laravel을 사용하여 이미지 처리 기능을 구현하는 방법

Laravel 개발 조언: 이미지 처리 및 캐싱을 최적화하는 방법 Laravel 개발 조언: 이미지 처리 및 캐싱을 최적화하는 방법 Nov 22, 2023 am 09:17 AM

Laravel 개발 조언: 이미지 처리 및 캐싱을 최적화하는 방법

이미지 처리를 위해 Hyperf 프레임워크를 사용하는 방법 이미지 처리를 위해 Hyperf 프레임워크를 사용하는 방법 Oct 24, 2023 pm 12:04 PM

이미지 처리를 위해 Hyperf 프레임워크를 사용하는 방법

PHP 프레임워크 및 CMS 통합: 기술 통합을 위한 무한한 가능성 PHP 프레임워크 및 CMS 통합: 기술 통합을 위한 무한한 가능성 Jun 01, 2024 pm 05:16 PM

PHP 프레임워크 및 CMS 통합: 기술 통합을 위한 무한한 가능성

공개된 Java 개발 기술: 이미지 처리 및 워터마킹 기능 구현 공개된 Java 개발 기술: 이미지 처리 및 워터마킹 기능 구현 Nov 20, 2023 pm 12:56 PM

공개된 Java 개발 기술: 이미지 처리 및 워터마킹 기능 구현

Imperial CMS 디렉토리 위치 공개 Imperial CMS 디렉토리 위치 공개 Mar 12, 2024 pm 10:33 PM

Imperial CMS 디렉토리 위치 공개

Java 개발의 이미지 처리 기술에 대한 심층적인 이해 Java 개발의 이미지 처리 기술에 대한 심층적인 이해 Nov 20, 2023 pm 01:29 PM

Java 개발의 이미지 처리 기술에 대한 심층적인 이해

비디오 트랜스코딩 서비스 구현을 위한 PHP 클라우드 트랜스코딩 CMS 시스템 구축 비디오 트랜스코딩 서비스 구현을 위한 PHP 클라우드 트랜스코딩 CMS 시스템 구축 Mar 16, 2024 am 08:30 AM

비디오 트랜스코딩 서비스 구현을 위한 PHP 클라우드 트랜스코딩 CMS 시스템 구축

See all articles