?php exit('dedecms');?,包罗万象的织梦CMS的图片处理类库
原标题:包罗万象的织梦CMS的图片处理类库
各位朋友大家好!
今天给大家带来的是一款 包罗万象的织梦CMS的图片处理类库!
包含:1.生成缩略图 2.图片水印 3.使用gd生成缩略图 4.使用gd进行水印
由于源码比较多,想要源文件的朋友 可以来我的PHP交流裙:157531900 每天都会上传一些类库,技术分享!欢迎各路小白和大神的加入!
好了,废话不多说!上源码!
/**
* 图像处理类
*
* @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') ? '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返回搜狐,查看更多
责任编辑:
?php exit('dedecms');?,包罗万象的织梦CMS的图片处理类库相关推荐
- dedecms wxjk.php_织梦cms集成微信公众平台功能 织梦文章同步微信公众号就是这么简单...
目前网上有很多这方面教程,关于dedecms微信插件,写的很详细,但是都是微信跳转的是PC网页,很难看,排版就乱了,今天南宫在这里介绍,如何跳转到dedecms织梦自带wap端,也就是跳到同内容的手机 ...
- dede image.class.php,织梦CMS中图片处理类
代码<?php if(!defined('DEDEINC')) exit('dedecms'); /** * 图像处理类 * * @version $Id: image.class.php 1 ...
- 织梦CMS粘贴图片自动上传到服务器(Java版)
如何做到 ueditor批量上传word图片? 1.前端引用代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...
- php不建议用织梦cms,你不得不知的织梦cms安全性设置常识 - DeDecms
你不得不知的织梦cms安全性设置常识 用过织梦cms的朋友了,这里就不多说了,织梦cms相对来说还是比较简单易用的,至于织梦cms的安全性如何,是否存在漏洞,这个问题来讲是不可避免的,当然了,这里也不 ...
- dedecms(织梦cms)安装99bill(快钱)支付方式接口
dedecms(织梦cms)涉及交易的有两个地方,其一是前台商品购物车,其二是用户中心充值与会员升级. 下面以用户中心充值与会员升级部分来说一下99bill(快钱)接口的安装,安装过之后,其前台商城的 ...
- 织梦 PHP和帝国哪个好,织梦CMS(dedecms)和帝国CMS哪个好
织梦CMS和帝国CMS都是很不错的建站程序,个人都曾经使用过,功能都非常的强大,如果非要说织梦CMS(dedecms)和帝国CMS哪个好的话,个人觉得织梦CMS的使用用户更多一些,使用起来也比较方便一 ...
- 织梦CMS(dedecms)栏目属性及系统封面模板、列表模板、文章模板区别和路径设置解答...
问题一:(织梦"栏目管理"的"常规选项"中3个栏目属性分析?) 织梦CMS的栏目属性分成三种, -->最终列表栏目 -->频道封面 -->外部 ...
- 织梦CMS(dedecms)栏目属性及系统封面模板、列表模板、文章模板区别和路径设置解答
问题一:(织梦"栏目管理"的"常规选项"中3个栏目属性分析?) 织梦CMS的栏目属性分成三种, -->最终列表栏目 -->频道封面 -->外部 ...
- 织梦wap.php绑定域名,dedecms织梦cms 手机站移动端 绑定设置独立M或wap域名的方法...
织梦根目录下的m文件夹就是手机网站访问的目录,所以我们要给http://www.sbwl.cn/m 绑定手机域名,使其成为http://m.sbwl.cn. 这样我们要做域名解析到m文件夹,之后在网站 ...
最新文章
- php 查oracle 表不存在报错处理,Oracle ORA-08104报错处理方法及注意事项
- mysql二进制日志文件差不多_mysql数据同步-基于二进制日志文件和position复制点的方式...
- Visual Studio 2005中web.sitemap 中扩展自定义属性的一些应用范例
- LeetCode 1722. 执行交换操作后的最小汉明距离(并查集)
- 项目vue2.0仿外卖APP(五)
- windows winrar 指令_WINRAR 命令行语法
- 如何优雅地制作精排 ePub —— 个人电子书制作规范及基本样式表
- Echarts绘制中国地图
- 【2022年Spring全家桶】Spring5.x 框架详解
- 东财《组织行为学X》综合作业
- mysql中FIND_IN_SET函数用法
- [转]禅修程序员十诫
- 大学毕业4年-回顾和总结(3)-投资理财观-图穷而真相现
- ALV能否实现自动小计
- Android开发、adb、monkey测试
- ps制作20种特效文字_如何使用会声会影进行质感文字制作——动态扫光浮雕特效...
- 实时音视频通信(RTC)中必须要了解的三种关键算法
- 树莓派系统剪裁、克隆
- android x86引导修复,Android-x86 9.0-r2 发布,更新内核与UEFI引导修复
- 你要记得那些大雨中为你撑伞的人,帮你挡住外来之物的人。。。——村上春树 2021.11.13日 早上11点
热门文章
- 【FLV】GO源码:解析http flv输出 GOP 和 对应关键帧TAG信息
- 解决jmeter 处理大数据量结果返回导致jmeter卡死的问题
- FinalShell安装与平民化使用
- Android之SeekBar(0在中间)
- c语言float气压,STM32+MS5611测气压温度例程详解,测试无误
- 【科普】关于操作系统(桌面操作系统/服务器操作系统/嵌入式/移动设备操作系统)基础概念
- python星星排列代码怎么写_【读码】python中的小星星*用法示例
- 安装mysql tomat jdk
- 行政管理系统-基于php,基于thinkphp,yxcms
- python中用来返回序列的最大函数_Python程序设计2——列表和元组