I'm currently writing a middleware to detect when a file is being uploaded to manipulate it. The aim is to detect any/all images on the application that have a height or width that is larger than 500px, and if it does then resize it before allowing the request to continue.
At the moment I have this middleware with this image loop
class CheckImageSizes
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//Get each of the files that are being uploaded in the request, if there are no files this will just be ignored.
foreach (array_flatten($request->files->all()) as $file) {
$image = Image::make($file);
if($image->height() > 500 || $image->width() > 500){
//Resize the image here and replace it in the request
}
}
return $next($request);
}
}
Inside my if statement, how would i replace the image in the request and then return it so that when my controller processes the image, it handles the newly resized image?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire