织梦手机wap模板下载(织梦怎么用)

  各位朋友大家好!

  今天给大家带来的是一款 包罗万象的织梦CMS的图片处理类库!

  包含:1.生成缩略图 2.图片水印 3.使用gd生成缩略图 4.使用gd进行水印

由于源码比较多,想要源文件的朋友 可以来我的PHP交流裙:157531900 每天都会上传一些类库,技术分享!欢迎各路小白和大神的加入!

  好了,废话不多说!上源码!

  <?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;

织梦手机wap模板下载(织梦怎么用)

  $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') ? 'imagecreatefromjpeg' : '';

  $this->imagefunc = function_exists('imagejpeg') ? 'imagejpeg' : '';

  break;

  case 'image/gif':

  $this->imagecreatefromfunc = function_exists('imagecreatefromgif') ? 'imagecreatefromgif' : '';

  $this->imagefunc = function_exists('imagegif') ? 'imagegif' : '';

  break;

  case 'image/png':

  $this->imagecreatefromfunc = function_exists('imagecreatefrompng') ? 'imagecreatefrompng' : '';

  $this->imagefunc = function_exists('imagepng') ? 'imagepng' : '';

  break;

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

  $this->attach['size'] = empty($this->attach['size']) ? @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 ? 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 ? '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 ? ($this->thumbstatus == 1 ? $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 ? 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 ? DEDEDATA.'/mark/mark.png' : DEDEDATA.'/mark/mark.gif';

  $watermarkinfo = @getimagesize($watermark_file);

  $watermark_logo = $this->watermarktype == 1 ? @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 ? $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


【免责声明】:

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。

【关于转载】:

本站尊重互联网版权体系,本站部分图片、文章大部分转载于互联网、所有内容不代表本站观点、不对文章中的任何观点负责、转载的目的只用于给网民提供信息阅读,无任何商业用途,所有内容版权归原作者所有
如本站(文章、内容、图片、视频)任何资料有侵权,先说声抱歉;麻烦您请联系请后台提交工单,我们会立即删除、维护您的权益。非常感谢您的理解。

【附】:

二○○二年一月一日《计算机软件保护条例》第十七条规定:为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬!鉴于此,也希望大家按此说明研究软件!

注:本站资源来自网络转载,版权归原作者和公司所有,如果有侵犯到您的权益,请第一时间联系我们处理!

-----------------------------------------------------------------------------------------------------------

【版权声明】:

一、本站致力于为源码爱好者提供国内外软件开发技术和软件共享,着力为用户提供优资资源。
二、本站提供的源码下载文件为网络共享资源,请于下载后的24小时内删除。如需体验更多乐趣,还请支持正版。
三、如有内容侵犯您的版权或其他利益的,请编辑邮件并加以说明发送到站长邮箱。站长会进行审查之后,情况属实的会在三个工作日内为您删除。
-----------------------------------------------------------------------------------------------------------


内容投诉
源码村资源网 » 织梦手机wap模板下载(织梦怎么用)

1 评论

您需要 登录账户 后才能发表评论

发表评论

欢迎 访客 发表评论