I have image compression happening in my backend like this:
private function storeImage($request){
$image = $request->file('image');
$input= time().$image->getClientOriginalName();
$destinationPath = '../public_html/images';
$img = Image::make($image->getRealPath());
$img->resize(900, 675, function($constraint){
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input, 70);
return $input;
}
The problem with this is that first the image has to be uploaded to the server and then it is compressed on the server. It works but it is really slow on slow internet connections. I have found this JavaScript library https://github.com/fengyuanchen/compressorjs/blob/main/README.md The problem I have is that I want to grab the compressed file on the backend and not upload it directly like the documentation says. I want the file to be reachable trough a request like it is now. Any suggestions, can I pass the compressed file to a hidden input and then grab it from the backend?
Aucun commentaire:
Enregistrer un commentaire