0 17 2025-12-21 18:34:33
收藏
/e/class/gd.php
初始源码如下
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;
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;
}
}
} else {
$srcX = 0;
$srcY = 0;
$tempx = $big_width;
$tempy = $big_height;
}
$new_width = ($ratiow > 1) ? $big_width : $max_width;
$new_height = ($ratioh > 1) ? $big_height : $max_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;
}
function ResizeImage($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1){
$returnr['file']='';
$returnr['filetype']='';
$JPG_QUALITY = 80; //jpg图片质量,最高100
$PNG_COMPRESS = 8; //png压缩率,最高9
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;
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;
}
}
} else {
$srcX = 0;
$srcY = 0;
$tempx = $big_width;
$tempy = $big_height;
}
$new_width = ($ratiow > 1) ? $big_width : $max_width;
$new_height = ($ratioh > 1) ? $big_height : $max_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);
if ($func_output == 'imagejpeg' || $func_output == 'image2wbmp') {
$func_output($temp_image, $new_name.$func_exname, $JPG_QUALITY);
} elseif ($func_output == 'imagepng') {
$func_output($temp_image, $new_name.$func_exname, $PNG_COMPRESS);
} else {
$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;
}
<?=sys_ResizeImg($bqr3['titlepic'],288, 192, 1)?>本文地址:https://xzo.com.cn/develop/empire/1318.html

如果您认可我们的分享,有意与我们合作开展帝国cms网站建设与开发业务或插件定制,请联系右侧在线客服。我们能给您的,就是高质量的模板与售后。
标注了信息来源为下载鸥的文章皆为原创,如果是转载的优质文章,我们也都标注了出处。如果您喜欢我们的文章,请按照下载鸥所标注的文章出处进行标注,谢谢您的配合。

帝国cms是一款功能极为强大的cms程序,性能强悍、安全性高,可轻松支持10万数据,高级开发人员可制作出能容纳千万数据量的网站,是国内最出色的开源cms程序之一,推荐企业用户使用。
当前最新版本为7.5,8.0版本即将上线,新版本的核心优化点在于多终端的适配。
帝国CMS后台信息列表标题文字字数默认是被控制过的,超出一行会截断,一些相对...
帝国cms是带有远程保存图片、图片加水印功能的,但都是默认未勾选的状态,我们...
帝国CMS是一款相当安全的开源cms程序,如果使用规范的模板,一般是不会被挂马的...
帝国cms自带的信息反馈功能,不仅可以实现留言功能,还可以实现像在线报名、反...
在企业站点建设过程中,我们常需要用到中英文双语。但模板尚且好说,分页的文字...
想要在帝国cms后台禁止发布标题相同的信息,或是在发布信息时验证一下标题是...
帝国cms图片集非常好用,通过合理配置图片集,我们可以实现网站图集的展示,让页...
微信作为我们的国民app流量很大,简单的js分享往往只有一个二维码或者链接,但...
通过本插件,可以实现帝国cms网站对接百度云api实现图像无损放大的功能。经过...
本插件基于帝国cms帝国cms每日自动审核插件,在自动审核指定条数信息的基础上...
通过本插件,可以实现帝国cms网站对接百度云api实现图像清晰度增强的功能。经...
许多网站会做一些小功能小插件给客户使用以增强用户黏性,比如图片转文字,这种...
本插件适用于内网用户,可查看单篇文章访问者ip地址。如果添加访问者ip组,可查...
帝国cms有自带的给关键词添加内链功能,但需要手动添加关键词,容易出现疏漏和...
百度开放了系列AI功能api如图像上色、图像去雾、图像修复、无损放大、清晰...
一直没看到好用的帝国cms在线考试插件,所以自己开发了一款。在线考试插件用...