Is it possible to reduce image size proportionally by standard laravel methods, without third-party libraries? My way to upload images to the server

$path = $request->file('image')->store('uploads','public'); 

If anyone is interested in how I did:

Used Intervention

  $file = $request->file('image'); //get filename with extension $filenamewithextension = $file->getClientOriginalName(); //get filename without extension $filename = pathinfo($filenamewithextension, PATHINFO_FILENAME); //get file extension $extension = $file->getClientOriginalExtension(); //filename to store $filenametostore = $filename.'_'.uniqid().'.'.$extension; \Storage::put('public/profile_images/'. $filenametostore, fopen($file, 'r+')); //Resize image here $thumbnailpath = public_path('storage/profile_images/'.$filenametostore); $img = Image::make($thumbnailpath); $height = $img->height(); $width = $img->width(); if($height >= 601) { $img->resize(300, null, function ($constraint) { $constraint->aspectRatio(); }); } if($width >= 601) { $img->resize(null, 300, function ($constraint) { $constraint->aspectRatio(); }); } $img->save($thumbnailpath); 

1 answer 1

Yes, do this: use Image: use Intervention \ Image \ Facades \ Image;

in code

 $img = Image::make('public/foo.jpg') // resize the image to a width of 300 and constrain aspect ratio (auto height) $img->resize(300, null, function ($constraint) { $constraint->aspectRatio(); });