検索
摘自织梦CMS中的图片处理类_PHPMay 30, 2016 am 08:47 AM
画像処理クラスドリームウィーバーcms

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

<&#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 までご連絡ください。
织梦cms忘记密码怎么办织梦cms忘记密码怎么办Mar 08, 2023 am 09:39 AM

织梦cms忘记密码的解决办法:1、登录MySql,找到网站对应的数据库的名称,点击进入该数据库;2、找到dede_admin表,然后找到管理员相关信息行并选中;3、通过还原的方式将密码还原为初始值,将pwd的值修改为默认的“f297a57a5a743894a0e4”即可。

织梦cms系统有收费的吗织梦cms系统有收费的吗Aug 11, 2023 pm 01:57 PM

织梦cms系统没有收费。织梦CMS是一款开源的内容管理系统,其核心代码是免费提供的,用户可以免费下载最新版本的织梦CMS,并且还可以获取相关的技术支持和文档。但在使用过程中,用户可能需要购买额外的功能模块或者主题模板,这些是收费的,购买这些收费的模块和模板,价格根据具体的功能和设计复杂度而定。

织梦cms安全性怎么样织梦cms安全性怎么样Jul 27, 2023 pm 05:32 PM

织梦cms安全性相对比较好,其原因有:1、漏洞修复速度快;2、CSRF(跨站点请求伪造)保护;3、XSS(跨站脚本攻击)保护;4、SQL注入保护;5、代码审计。

织梦cms是什么语言写的织梦cms是什么语言写的Feb 21, 2023 am 09:45 AM

织梦cms是用PHP语言写的。织梦CMS(DedeCMS)是一个PHP开源网站管理系统,作用是构建中小型网站;它采用PHP+MySQL技术开发,可同时使用于windows、linux、unix平台。

织梦cms连接数据库失败怎么办织梦cms连接数据库失败怎么办Jul 20, 2023 pm 02:22 PM

织梦cms连接数据库失败解决方法:1、检查数据库配置,确保在织梦CMS的根目录下的 /data/config.php 文件中正确设置了数据库的相关信息;2、测试数据库连接,通过创建一个简单的PHP脚本来测试数据库连接是否成功;3、检查数据库服务器状态,在织梦CMS的根目录下的 /data/config.php 文件中更换数据库服务器地址;4、检查网络连接。

织梦cms数据库名称怎么修改织梦cms数据库名称怎么修改Feb 28, 2023 am 09:39 AM

织梦cms数据库名称的修改方法:1、直接修改mysql里的数据库名称;2、打开根目录下的“data”文件夹,然后找到“common.inc.php”文件;3、修改其中“$cfg_dbname”后面的数据即可。

织梦cms主要是做什么的织梦cms主要是做什么的Aug 08, 2023 pm 03:24 PM

织梦cms主要是做网站的建设、管理和维护。1、网站建设,织梦CMS提供了丰富的模板和插件资源,用户可以根据自己的需求选择合适的模板和插件,快速搭建自己的网站;2、网站管理,织梦CMS提供了简单易用的管理后台界面,用户可以通过浏览器登录后台进行网站管理;3、网站维护,织梦CMS提供了自动备份和数据库管理等功能,保证网站的安全和稳定运行。

织梦cms备案号位置怎么更改织梦cms备案号位置怎么更改Feb 27, 2023 am 09:46 AM

织梦cms备案号位置的更改方法:1、进入织梦后台,然后找到“模板”分类;2、点击“默认模板管理”;3、找到“footer.htm”,并点击修改;4、找到“{dede:global.cfg_powerby/}”,然后填写备案号即可。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール