当前位置:网站首页>Kindeditor editor upload image ultra wide automatic compression -php code
Kindeditor editor upload image ultra wide automatic compression -php code
2022-07-03 16:40:00 【Code 8 farmer】
kindeditor It's an open source editor , stay web Website editing is widely used , The built-in editor code can only limit the size , You can't limit the width and height of the picture , Sometimes the picture is too wide and very ugly , This article introduces kindeditor The editor uploads pictures with ultra wide automatic compression , Proportional compression , Directly reduce the size of the picture , Save a space , Speed up image loading .
Find the following file and open ,kindeditor\php\upload_json.php
Find this line of code :
$file_url = $save_url . $new_file_name;
Add the following code after :
compressedImage($_SERVER['DOCUMENT_ROOT'].$file_url,800);// The compressed image
The code above , You can also set the compression quality , See the following functions for specific functions
Then at the bottom of the file , Add the following 2 A function
/**
* desription Proportionally compressed picture author wfuyu.com
* @param sting $imgsrc Picture path
* @param string $imgdst Save path after compression , If it is empty , Coverage
,$zhiliang=90 Picture quality
$wd= If it exceeds this size, it will be compressed proportionally
*/
function compressedImage($imgsrc,$wd=600,$zhiliang=90,$imgdst=''){
if($imgdst==''){$imgdst=$imgsrc;}
list($width, $height, $type) = getimagesize($imgsrc);
$new_width = $width;// The compressed picture is wide
$new_height = $height;// The compressed picture is high
if($width >= $wd){
$per = $wd / $width;// Calculation scale
$new_width = $width * $per;
$new_height = $height * $per;
}
switch ($type) {
case 1:
$giftype = check_gifcartoon($imgsrc);
if ($giftype) {
// header('Content-Type:image/gif');
$image_wp = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromgif($imgsrc);
$bg =imagecolorallocate($image_wp, 255, 255, 255);
imagefill($image_wp, 0, 0, $bg);
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//90 It represents quality 、 Compressed picture size
imagejpeg($image_wp, $imgdst, $zhiliang);
imagedestroy($image_wp);
imagedestroy($image);
}
break;
case 2:
// header('Content-Type:image/jpeg');
$image_wp = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($imgsrc);
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//90 It represents quality 、 Compressed picture size
imagejpeg($image_wp, $imgdst, $zhiliang);
imagedestroy($image_wp);
imagedestroy($image);
break;
case 3:
//header('Content-Type:image/png');
$image_wp = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($imgsrc);
$bg =imagecolorallocate($image_wp, 255, 255, 255);
imagefill($image_wp, 0, 0, $bg);
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//90 It represents quality 、 Compressed picture size
imagejpeg($image_wp, $imgdst, $zhiliang);
imagedestroy($image_wp);
imagedestroy($image);
break;
}
}
function check_gifcartoon($image_file){ $fp = fopen($image_file,'rb');$image_head = fread($fp,1024);fclose($fp);return preg_match("/".chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0'."/",$image_head)?false:true;}边栏推荐
- MySQL converts comma separated attribute field data from column to row
- PHP CI(CodeIgniter)log级别设置
- [combinatorics] polynomial theorem (polynomial coefficients | full arrangement of multiple sets | number of schemes corresponding to the ball sub model | polynomial coefficient correlation identity)
- Summary of three methods of PHP looping through arrays list (), each (), and while
- How to initialize views when loading through storyboards- How is view initialized when loaded via a storyboard?
- Mysql 单表字段重复数据取最新一条sql语句
- PHP二级域名session共享方案
- Record windows10 installation tensorflow-gpu2.4.0
- [combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
- What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
猜你喜欢

于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日

What kind of material is 14Cr1MoR? Analysis of chemical composition and mechanical properties of 14Cr1MoR

斑马识别成狗,AI犯错的原因被斯坦福找到了

Unreal_ Datatable implements ID self increment and sets rowname

TCP congestion control details | 3 design space

What is the material of sa302grc? American standard container plate sa302grc chemical composition

word 退格键删除不了选中文本,只能按delete

MySQL single table field duplicate data takes the latest SQL statement

Simulink oscilloscope data is imported into Matlab and drawn

【LeetCode】94. Middle order traversal of binary tree
随机推荐
Is it safe to open a stock account by mobile registration? Does it need money to open an account
【剑指 Offer 】64. 求1+2+…+n
PHP中register_globals参数设置
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
Add color to the interface automation test framework and realize the enterprise wechat test report
Unity项目优化案例一
Interviewer: how does the JVM allocate and recycle off heap memory
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
Explore Netease's large-scale automated testing solutions see here see here
探索Cassandra的去中心化分布式架构
NSQ source code installation and operation process
Register in PHP_ Globals parameter settings
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Why does the std:: string operation perform poorly- Why do std::string operations perform poorly?
Arduino esp32: overall framework of lvgl project (I)
Pointcut expression
Golang 装饰器模式以及在NSQ中的使用
Eleven requirements for test management post
Mongodb installation and basic operation