简体   繁体   中英

How to optimize image after crop using php?

I am using https://foliotek.github.io/Croppie/ plugin for the cropping image. 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. I want to reduce the size of the image after cropping. I need in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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