您现在的位置是:首页 > cms教程 > 帝国CMS教程帝国CMS教程
怎么去掉帝国CMS缩略图自动出现黑边框背景
陈莉汐2023-05-21帝国CMS教程已有人查阅
导读近期优化网站解决的的问题,帝国CMS自动缩略图会出现黑边框背景,很丑。看了GD库,发现没什么改的,网上找了下方法,完美解决了,分享下。

近期优化网站解决的的问题,帝国CMS自动缩略图会出现黑边框背景,很丑。看了GD库,发现没什么改的,网上找了下方法,完美解决了,分享下。
sys_ResizeImg函数去黑边方法
第一种方式 帝国默认:
sys_ResizeImg($r[titlepic],宽,高,0);//帝国默认的不裁剪缩放生成缩略图的方式
第二种方式 帝国默认:
sys_ResizeImg($r[titlepic],宽,高,1);//帝国默认的裁剪缩放生成缩略图的方式
第三种方式 去掉裁剪不够时的黑边并且从图片缩放后中间裁剪:
sys_ResizeImg($r[titlepic],宽,高,2);//新加去黑边裁剪生成缩略图的方式
第四种方式 只固定图片的宽,高度不限制(类似不规则瀑布流的图片形式),高填写为大于0的任意整数数字:
sys_ResizeImg($r[titlepic],宽,高,3);//新加去黑边生成类似瀑布流格式的方式
/e/class/gd.php 函数全部代码如下:
<?php
define('InEmpireCMSGd',TRUE);
//原文件,新文件,宽度,高度,维持比例
function ResizeImage($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1){
$returnr['file']='';
$returnr['filetype']='';
if($temp_img_type = @getimagesize($big_image_name)) {preg_match('//([a-z]+)$/i', $temp_img_type[mime], $tpn); $img_type = $tpn[1];}
else {preg_match('/.([a-z]+)$/i', $big_image_name, $tpn); $img_type = $tpn[1];}
$all_type = array(
"jpg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),
"gif" => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif" , "exn"=>".gif"),
"jpeg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),
"png" => array("create"=>"imagecreatefrompng" , "output"=>"imagepng" , "exn"=>".png"),
"wbmp" => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
);
$func_create = $all_type[$img_type]['create'];
if(empty($func_create) or !function_exists($func_create))
{
return $returnr;
}
//输出
$func_output = $all_type[$img_type]['output'];
$func_exname = $all_type[$img_type]['exn'];
if(($func_exname=='.gif'||$func_exname=='.png'||$func_exname=='.wbmp')&&!function_exists($func_output))
{
$func_output='imagejpeg';
$func_exname='.jpg';
}
$big_image = $func_create($big_image_name);
$big_width = imagesx($big_image);
$big_height = imagesy($big_image);
if($big_width <= $max_width and $big_height <= $max_height)
{
$func_output($big_image, $new_name.$func_exname);
$returnr['file']=$new_name.$func_exname;
$returnr['filetype']=$func_exname;
return $returnr;
}
$ratiow = $max_width / $big_width;
$ratioh = $max_height / $big_height;
$new_width = ($ratiow > 1) ? $big_width : $max_width;
$new_height = ($ratioh > 1) ? $big_height : $max_height;
if($resize == 1) {
if($big_width >= $max_width and $big_height >= $max_height)
{
if($big_width > $big_height)
{
$tempx = $max_width / $ratioh;
$tempy = $big_height;
$srcX = ($big_width - $tempx) / 2;
$srcY = 0;
} else {
$tempy = $max_height / $ratiow;
$tempx = $big_width;
$srcY = ($big_height - $tempy) / 2;
$srcX = 0;
}
} else {
if($big_width > $big_height)
{
$tempx = $max_width;
$tempy = $big_height;
$srcX = ($big_width - $tempx) / 2;
$srcY = 0;
} else {
$tempy = $max_height;
$tempx = $big_width;
$srcY = ($big_height - $tempy) / 2;
$srcX = 0;
}
}
}elseif($resize == 2){//同比例缩放超出裁切
if($big_width >= $max_width and $big_height >= $max_height)
{
if($max_width > ($big_width * $ratioh)){
$tempx=$big_width;
$tempy=$max_height / $ratiow;
$srcX=0;
$srcY=($big_height - $tempy) / 2;
}elseif($max_height > ( $big_height * $ratiow)){
$tempx=$max_width / $ratioh;
$tempy=$big_height;
$srcX=($big_width - $tempx) / 2;
$srcY=0;
}
}else{
if($max_height > $big_height){
$tempx=$max_width;
$tempy=$big_height;
$srcX=($big_width - $max_width) / 2;
$srcY=0;
}elseif($max_width > $big_width){
$tempx=$big_width;
$tempy=$max_height;
$srcX=0;
$srcY=($big_height - $max_height) / 2;
}
}
}elseif($resize == 3){//宽度固定 高度同比例任意
$srcX = 0;
$srcY = 0;
$tempx = $big_width;
$tempy = $big_height;
if($big_width >= $max_width){
$new_height=$big_height*$ratiow;
}else{
$new_height=$big_height;
}
}else { //不保持比例
$srcX = 0;
$srcY = 0;
$tempx = $big_width;
$tempy = $big_height;
}
if(function_exists("imagecopyresampled"))
{
$temp_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);
} else {
$temp_image = imagecreate($new_width, $new_height);
imagecopyresized($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);
}
$func_output($temp_image, $new_name.$func_exname);
ImageDestroy($big_image);
ImageDestroy($temp_image);
$returnr['file']=$new_name.$func_exname;
$returnr['filetype']=$func_exname;
return $returnr;
}
/*
* 功能:图片加水印 (水印支持图片或文字)
* 参数:
* $groundImage背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterPos水印位置,有10种状态,0为随机位置;
*1为顶端居左,2为顶端居中,3为顶端居右;
*4为中部居左,5为中部居中,6为中部居右;
*7为底端居左,8为底端居中,9为底端居右;
* $waterImage图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterText文字水印,即把文字作为为水印,支持ASCII码,不支持中文;
* $textFont文字大小,值为1、2、3、4或5,默认为5;
* $textColor文字颜色,值为十六进制颜色值,默认为#FF0000(红色);
* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG
* $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。
* 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。
* 加水印后的图片的文件名和 $groundImage 一样。
*/
function imageWaterMark($groundImage,$waterPos=0,$waterImage="",$waterText="",$textFont=5,$textColor="#FF0000",$myfontpath="../data/mask/cour.ttf",$w_pct,$w_quality){
global $fun_r,$editor;
if($editor==1){$a='../';}
elseif($editor==2){$a='../../';}
elseif($editor==3){$a='../../../';}
else{$a='';}
$waterImage=$waterImage?$a.$waterImage:'';
$myfontpath=$myfontpath?$a.$myfontpath:'';
$isWaterImage = FALSE;
$formatMsg = $fun_r['synotdotype'];
//读取水印文件
if(!empty($waterImage) && file_exists($waterImage))
{
$isWaterImage = TRUE;
$water_info = getimagesize($waterImage);
$water_w= $water_info[0];//取得水印图片的宽
$water_h= $water_info[1];//取得水印图片的高
switch($water_info[2])//取得水印图片的格式
{
case 1:$water_im = imagecreatefromgif($waterImage);break;
case 2:$water_im = imagecreatefromjpeg($waterImage);break;
case 3:$water_im = imagecreatefrompng($waterImage);break;
default:echo $formatMsg;return "";
}
}
//读取背景图片
if(!empty($groundImage) && file_exists($groundImage))
{
$ground_info = getimagesize($groundImage);
$ground_w= $ground_info[0];//取得背景图片的宽
$ground_h= $ground_info[1];//取得背景图片的高
switch($ground_info[2])//取得背景图片的格式
{
case 1:$ground_im = imagecreatefromgif($groundImage);break;
case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
case 3:$ground_im = imagecreatefrompng($groundImage);break;
default:echo $formatMsg;return "";
}
}
else
{
echo $fun_r['synotdoimg'];
return "";
}
//水印位置
if($isWaterImage)//图片水印
{
$w = $water_w;
$h = $water_h;
$label = "图片的";
}
else//文字水印
{
$temp = imagettfbbox(ceil($textFont*2.5),0,$myfontpath,$waterText);//取得使用 TrueType 字体的文本的范围
$w = $temp[2] - $temp[6];
$h = $temp[3] - $temp[7];
unset($temp);
$label = "文字区域";
}
if( ($ground_w<$w) || ($ground_h<$h) )
{
echo $fun_r['sytoosmall'];
return '';
}
switch($waterPos)
{
case 0://随机
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
case 1://1为顶端居左
$posX = 0;
$posY = 0;
break;
case 2://2为顶端居中
$posX = ($ground_w - $w) / 2;
$posY = 0;
break;
case 3://3为顶端居右
$posX = $ground_w - $w;
$posY = 0;
break;
case 4://4为中部居左
$posX = 0;
$posY = ($ground_h - $h) / 2;
break;
case 5://5为中部居中
$posX = ($ground_w - $w) / 2;
$posY = ($ground_h - $h) / 2;
break;
case 6://6为中部居右
$posX = $ground_w - $w;
$posY = ($ground_h - $h) / 2;
break;
case 7://7为底端居左
$posX = 0;
$posY = $ground_h - $h;
break;
case 8://8为底端居中
$posX = ($ground_w - $w) / 2;
$posY = $ground_h - $h;
break;
case 9://9为底端居右
$posX = $ground_w - $w;
$posY = $ground_h - $h;
break;
default://随机
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
}
//设定图像的混色模式
imagealphablending($ground_im, true);
if($isWaterImage)//图片水印
{
if($water_info[2]==3)
{
imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件
}
else
{
imagecopymerge($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h,$w_pct);//拷贝水印到目标文件
}
}
else//文字水印
{
if( !empty($textColor) && (strlen($textColor)==7) )
{
$R = hexdec(substr($textColor,1,2));
$G = hexdec(substr($textColor,3,2));
$B = hexdec(substr($textColor,5));
}
else
{
echo $fun_r['synotfontcolor'];
return "";
}
imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
}
//生成水印后的图片
@unlink($groundImage);
switch($ground_info[2])//取得背景图片的格式
{
case 1:imagegif($ground_im,$groundImage);break;
case 2:imagejpeg($ground_im,$groundImage,$w_quality);break;
case 3:imagepng($ground_im,$groundImage);break;
default:echo $formatMsg;return "";
}
//释放内存
if(isset($water_info)) unset($water_info);
if(isset($water_im)) imagedestroy($water_im);
unset($ground_info);
imagedestroy($ground_im);
}
?>
后台自动缩略图去黑边方法,系统参数-系统参数设置-图片设置-超出部分是否截取,去掉勾选
本文标签:
很赞哦! ()
图文教程
帝国CMS8.0新增登录后台需激活功能使用流程
帝国CMS8.0版新增后台登录激活功能:可以设置管理员每次登录都需要高管理员同意后才能进后台。后台登录激活功能使用流程为如下:
帝国cms灵动标签常用变量和使用技巧介绍
1、灵动标签添是否加单引号的区别,2、灵动标签的标签注释,3、灵动标签常用格式<?=$bqr[title]?>和<?=$bqr['title']?>的区别,答案:必须加单引号(''),这样速度快;
帝国7.5默认编辑器增加代码高亮的方法
需要下载的插件及依赖工具,将下载的插件解压,并复制到帝国的ckeditor目录下,注意是后台的那个默认后台目录:eadminecmseditorinfoeditorplugins
帝国CMS整合ueditor 1.4.3百度编辑器的方法
帝国CMS7.5终于更新了自带的后台编辑器,但功能还是太少且很多地方有问题,所以很多人还是愿意用帝国CMS7.5整合了ueditor 1.4.3百度编辑器 UTF-8版本
相关源码
-
(自适应响应式)WORDwps办公资源教程资讯网站模板下载基于PbootCMS内核开发的响应式网站模板,为办公教程、WPS技巧分享、职场技能培训等场景打造。模板内置标准化文档分类体系,支持图文/视频教程混合展示,满足现代办公知识传播需求。查看源码 -
(自适应)大气办公用品耗材供应打印机产品维修网站模板下载基于PbootCMS系统开发的响应式网站模板,为营销技术博主、数字产品评测者设计。采用前沿的响应式技术,确保内容在手机端和桌面端都能获得较佳阅读体验,帮助用户高效展示技术文章和产品分析。查看源码 -
(自适应响应式)蓝色外贸英文产品介绍展示网站模板本模板采用手工编写的DIV+CSS架构,代码精简高效。适配手机端浏览,数据实时同步更新。内置SEO优化框架,支持独立设置各页面标题、关键词及描述。开源代码结构清晰,便于二次开发。查看源码 -
(PC+WAP)蓝色公司注册财务会计公证律师网站源码下载本模板基于PbootCMS内核开发,为财务会计事务所、律师公证机构等专业服务机构打造。采用自适应设计,确保在各类设备上都能呈现专业视觉效果,帮助机构建立值得信赖的线上形象。查看源码 -
(自适应)居家生活日用品纸盘纸盒纸杯卫生纸巾生产厂家pbootcms模板为纸品生产企业打造的现代化展示平台,自动适应各种设备屏幕,确保浏览体验一致,完善的SEO功能,提升网站曝光度,基于PbootCMS构建,源码开放可定制。查看源码 -
(PC+WAP)历史复古古典古籍文章资讯类pbootcms模板下载本模板基于PbootCMS系统开发,为古籍研究、历史文献类网站设计,特别适合展示古典书籍、历史档案等文化内容。采用复古风格设计,同时具备现代化响应式布局,确保在PC和移动设备上都能呈现优雅的阅读体验。查看源码
| 分享笔记 (共有 篇笔记) |

