简体   繁体   English

如何使用php优化裁剪后的图像?

[英]How to optimize image after crop using php?

I am using https://foliotek.github.io/Croppie/ plugin for the cropping image. 我正在使用https://foliotek.github.io/Croppie/插件来裁剪图像。 Everything is working perfectly. 一切工作正常。 I am able to crop the image and after crop the image able to insert the image in my folder and database. 我能够裁剪图像,裁剪后的图像能够将图像插入到我的文件夹和数据库中。

The issue is sometimes I am getting image size 300kb and same time I am getting the image more than 5MB or 10 MB. 问题有时是我获得的图像大小为300kb,而同时获得的图像超过5MB或10 MB。 I want to reduce the size of the image after cropping. 我想在裁切后缩小图像的尺寸。 I need in KB 我需要KB

$data = $_POST['imagebase64'];
list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);
$imageName = time().'.png';
$destination_img= "images/profile/";
/*image optimizer code here*/

//help me with code

/*end optimizer code*/
file_put_contents('images/profile/'.$imageName, $data);

for quality you need to pass height and width as well. 为了获得质量,您还需要传递高度和宽度。 So if you want to keep the original height and width then you can use $data['width'] $data['height'], please check in your library if you have it or not. 因此,如果您想保留原始的高度和宽度,则可以使用$ data ['width'] $ data ['height'],请检查您的库是否有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM