当前位置:网站首页>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;}边栏推荐
- PHP CI (CodeIgniter) log level setting
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- [sword finger offer] 58 - I. flip the word order
- Mongodb installation and basic operation
- 14 topics for performance interviews between superiors and subordinates (4)
- 智慧之道(知行合一)
- The mixlab editing team is recruiting teammates~~
- 中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
- What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
- Caching mechanism of Hibernate / session level caching mechanism
猜你喜欢

探索Cassandra的去中心化分布式架构

Data driving of appium framework for mobile terminal automated testing

NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)

Aike AI frontier promotion (7.3)
![[statement] about searching sogk1997 and finding many web crawler results](/img/1a/8ed3ca0030ea227adcd95e8b306aca.png)
[statement] about searching sogk1997 and finding many web crawler results

PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug

Mysql 单表字段重复数据取最新一条sql语句

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

Multithread 02 thread join

The mixlab editing team is recruiting teammates~~
随机推荐
QT串口ui设计和解决显示中文乱码
Threejs Part 2: vertex concept, geometry structure
function overloading
【LeetCode】94. Middle order traversal of binary tree
NSQ source code installation and operation process
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
[combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
[combinatorics] non descending path problem (outline of non descending path problem | basic model of non descending path problem | non descending path problem expansion model 1 non origin starting poi
NSQ源码安装运行过程
(补)双指针专题
Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day
ThreeJS 第二篇:顶点概念、几何体结构
How programming apes grow rapidly
Extraction of the same pointcut
Custom plug-in construction and use of QT plug-in
Mysql 将逗号隔开的属性字段数据由列转行
What material is sa537cl1? Sa537cl1 corresponds to the national standard material
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Pointcut expression