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

《:摘自织梦CMS中的图片处理类》要点:
本文介绍了:摘自织梦CMS中的图片处理类,希望对您有用。如果有疑问,可以联系我们。

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

<?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,$attach);
 }
 // 析构函数
 function __construct($targetfile,$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') ? '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,$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,$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,$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,$imageheight);
    if($this->watermarktype == 1)
    {
     imagecopy($dst_photo,$watermark_logo,$x,$y,$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'],$x + $ax + $this->watermarktext['shadowx'],$y + $ay + $this->watermarktext['shadowy'],$shadowcolor,$this->watermarktext['text']);
     }
     $colorrgb = explode(',$this->watermarktext['color']);
     $color = imagecolorallocate($dst_photo,$colorrgb[0],$colorrgb[1],$colorrgb[2]);
     imagettftext($dst_photo,$x + $ax,$y + $ay,$color,$this->watermarktext['text']);
    }
    else
    {
     imagealphablending($watermark_logo,true);
     imagecopymerge($dst_photo,$logoheight,$this->watermarktrans);
    }
    $targetfile = !$preview ? $this->targetfile : './watermark_tmp.jpg';
    if($this->attachinfo['mime'] == 'image/jpeg')
    {
     $imagefunc($dst_photo,$this->watermarkquality);
    }
    else
    {
     $imagefunc($dst_photo,$targetfile);
    }
    $this->attach['size'] = filesize($this->targetfile);
   }
  }
 }
}//End Class

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

《:摘自织梦CMS中的图片处理类》是否对您有启发,欢迎查看更多与《:摘自织梦CMS中的图片处理类》相关教程,学精学透。编程之家 jb51.cc为您提供精彩教程。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


文章浏览阅读483次。dedecms织梦频道模板中调用栏目分类并排序:{dede:channelartlist}栏目排序:{dede:global runphp='yes' name=itemindex}@me;{/dede:global}<a href=”{dede:field name='typeurl' /}”>点击进入{dede:field name='typename' /}列表>></a>{/dede:channelartlist}织梦channel标签.._织梦 调取排序
文章浏览阅读284次。我们在用织梦建站的过程中,难免会遇到各种问题,有时候由于主机或者服务器无法支持某些函数或者不够稳定等,需要更换空间或服务器。这个时候我们如何完整地把织梦网站数据转移到新的空间或者服务器上,这是织梦站长必须掌握的技能之一。当然,网站搬家来说,方法是很多的,但是万变不离其宗,说到底就是程序文件和数据文件的备份转移。织梦DedeCMS网站转移主机或者服务器时最常见的转移方式,来说明一下网站搬家的过程。首先是织梦DedeCMS网站程序的数据库备份,方法是进入织梦Dedecms的后台,系统–> 数据库备_dede后台转主机需要修改哪些哪些东西
文章浏览阅读152次。seo专题是seo优化必不可少的一环,对于网站优化的意义重大,因为一些用内容页做不上去的关键词都可以尝试用专题形式来做。相对于一般性的网页来说,专题页面具有内容丰富性、多样性、用户体验好的特征,百度官方也在最近说了专题优化的好处。但是,专题对seo是好的,但是对于做专题的人来说却并不好做,因为他非常的繁琐和耗费功夫。从原理来说,一般性的网页(栏目、内容页)都是通过统一的模板进行映射的网页,这些网页的构成都非常的简单,虽然有些可以利用内容模型和自定义列表进行参数提取,这样让内容非常的丰富,但是这个丰富_织梦专题
文章浏览阅读142次。在Dedecms中,在列表页调用文章摘要的方法主要有:1:[field:info /]2:[field:description /]3:[field:info function="cn_substr(@me,字符数)"/]4:[field:description function="cn_substr(@me,字符数)"/]第1、2种方法是直接调用文章摘要,在调用的字数问题上,当使用[field:info /]时,可以在{dede:arclist infolen=' ' }{/dede:arcli_dede 内容摘要 字数
文章浏览阅读234次。织梦DedeCMS文章内容发布时可以选择“头条”、“推荐”、“特荐”等文档属性,我们可以利用这些条件加一个判断的标签,然后给文章列表加一个推荐的印戳图标,这样大大提高了页面的友好程度。文字推荐方法:[field:flag runphp='yes'] if(stristr(@me,"c")) @me = "[推荐]";else @me = '';[/field:flag][field:flag runphp='yes'] if(stristr(@me,"a")) @me = "[特荐]";else _dede 列表页 调用推荐文章
文章浏览阅读701次。虽然织梦DedeCMS因为安全问题被人所诟病,但瑕不掩瑜,无论从用户群数量还是时间等各方面,织梦DedeCMS都是国内排名前几的CMS建站程序。如果你想学习CMS的二次开发,织梦DedeCMS是必须需要研究的。对织梦DedeCMS的二次开发来说,了解织梦的目录构成、文件、函数则是必备的功课。今天整理一篇关于Dedecms目录介绍的文章,对织梦DedeCMS的目录结构、核心文件、模板文件等做一个简单的介绍。为使版面美观,就借用下php程序的注释,//符合后面为该文件的作用。由于版本的原因,有一_织梦默认模板目录
文章浏览阅读375次。dede是目前cms中使用最广泛的,也是中小网站中seo优化最好的(默认模板而言),所以很多的企业都会选择采用dede作为做站的首选,因此学seo了解些织梦seo优化的技巧和方面是有必要的。焦大曾经做过多年的织梦seo优化,以个人经验所知,觉得以下几个方面的seo最为重要:第一,url设置与栏目分开。我们看到目前90%以上的dede建站者的文章url都是类似域名/栏目名/文章ID,或者域名/a/日期/栏目/文章ID,其中第一种在企业站最常见,第二种在新闻资讯网站中常见。个人觉得这么设置会出._dede seo
文章浏览阅读189次。dedecms的arclist循环中,判断如果是第一个li,则添加固定的css,否则不加写法如下: 1 2 3 4 {dede:arclist row=4 flag='p'} <li [field:global name=autoindex runphp="yes"](@me==1)? @me="class=on":@me="";[/field:global]>[field:global.autoindex/]<.._dedecms arclist
文章浏览阅读227次。字段要想在任何位置任何模版中调用,需要特殊设置。自定义字段自定义的织梦如何添加自定义字段的频道模型,这里以图片集频道举例注意:创建字段可以在列表的底层模板中获得”这个必须勾选在字段中添加(价格属性)在基本设置里》列表附加调用)二,调用自定义调用{dede:list pagesize='5' addfields='jiage' channelid='2'}<P>标题:[field:title/]</P><P>价格:[field:jiage/]&_织梦列表调用自定义字段
本教程操作系统:Windows10系统、DedeCMS 5.7.109版本、Dell G3电脑。 织梦CMS是一个使用PHP语言开发的网站建设管理系统,因此在安装过程中需要安装数据库以存储网站内容和数据。
在Dedecms织梦列表页中是肯定要使用pagelist标签的,但是有的时候也会因为一些css格式的问题会出现排列顺序的问题,所以也要知道怎么样修改pagelist标签?
今天分享织梦网站怎么搬家,个人感觉织梦的搬家比其他的程序的都简单。1、网站备份登录织梦后台,【系统】-【数据库备份/还原】-【提交】,织梦程序开始自动备份数据库,等待即可。
织梦(dede)程序不安全是公认的,同样是建站,使用织梦程序被黑的风险更大,所以,一些安全设置是非常有必要的。织梦网站安全设置的4个主要操作
使用xemu、爱站工具包、尖叫青蛙等制作网站地图,每次生成sitemap还需要再上传到服务器,还是比较麻烦的,不过有些网站程序可以通过插件完成网站地图的自动更新,比如wordpress。但是织梦一直都不行,今天就用插件+代
分享织梦自动生成网站sitemap,但是需要安装插件,今天分享,织梦如何不使用插件,制作网站xml地图。
织梦自定义表单没有全选/取消全选功能,有时候想要全选全,需要一个一个选择比较麻烦,如果网站有大量的恶意留言,想要删除更麻烦。虽然可以使用sql命令删除恶意留言,但不是很灵活,今天就给织梦自定义表单添加全选
前几天百度公开课说了,api推送的优先级比较高,所以在没有快速收录的情况下,api提交必须要有,那么织梦要如何实现api主动推送呢?
dede定时主动推送,虽然也很方便,但只能固定时间推送,实时性不高,今天小编分享如何发布文章后实时api推送至百度?
dede当前位置标签代码方法一:{dede:fieldname='position'/}dede当前位置标签代码方法二:{dede:fieldname='position'runphp='yes'}$a=mb_strlen(@me);//计算字符串的长度@me=cn_substr(@me,$a-2,-1);//截取字符{/dede:field}(这是去掉“去掉>”得得方法)dede当前位置
织梦DEDECMS文章、栏目页获取当前页面顶级栏目名称的方法在用织梦做一些项目时,时常会碰到需要在当前页面调用顶级栏目名称的时候,织梦默认{dede:fieldname='typename'/}可以获取当前栏目页上一级栏目的名称,而不是当前栏目顶级栏目名称。下面拓展出一个方法来实现这个效果: 方