当前位置:网站首页>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;}边栏推荐
- Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes
- Data driving of appium framework for mobile terminal automated testing
- 一台服务器最大并发 tcp 连接数多少?65535?
- [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
- 2022爱分析· 国央企数字化厂商全景报告
- "The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
- ThreeJS 第二篇:顶点概念、几何体结构
- Overview of satellite navigation system
- 利用MySQL中的乐观锁和悲观锁实现分布式锁
- Cocos Creator 2.x 自动打包(构建 + 编译)
猜你喜欢

线程池执行定时任务

爱可可AI前沿推介(7.3)

QT串口ui设计和解决显示中文乱码

2022爱分析· 国央企数字化厂商全景报告

The word backspace key cannot delete the selected text, so you can only press Delete

面试官:JVM如何分配和回收堆外内存

8个酷炫可视化图表,快速写出老板爱看的可视化分析报告

Mysql 将逗号隔开的属性字段数据由列转行

NLP four paradigms: paradigm 1: fully supervised learning in the era of non neural networks (Feature Engineering); Paradigm 2: fully supervised learning based on neural network (Architecture Engineeri

Arduino esp32: overall framework of lvgl project (I)
随机推荐
2022爱分析· 国央企数字化厂商全景报告
Détails du contrôle de la congestion TCP | 3. Espace de conception
面试之 top k问题
Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
什么是质押池,如何进行质押呢?
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
PHP converts a one-dimensional array into a two-dimensional array
How to set up SVN server on this machine
TCP拥塞控制详解 | 3. 设计空间
Visual SLAM algorithms: a survey from 2010 to 2016
Summary of three methods of PHP looping through arrays list (), each (), and while
ThreeJS 第二篇:顶点概念、几何体结构
Unreal_DataTable 实现Id自增与设置RowName
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
远程办公之大家一同实现合作编辑资料和开发文档 | 社区征文
Deep understanding of grouping sets statements in SQL
Explore Cassandra's decentralized distributed architecture
Is it safe to open an account with flush?
[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
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告