Skip to content

Instantly share code, notes, and snippets.

@aquasmit
Last active December 19, 2016 04:01
Show Gist options
  • Save aquasmit/0122f0295e2b3a93e04772398b42c287 to your computer and use it in GitHub Desktop.
Save aquasmit/0122f0295e2b3a93e04772398b42c287 to your computer and use it in GitHub Desktop.
Laravel - perfect image resize in intervention

If you are using intervention in laravel for image resize then below snippet you can use to resize with max width and max height and maintaing aspect ration.

            
            $img = Image::make($file);            
            $new_filename = 'newname.'.$file->getClientOriginalExtension();	
            $img->widen(660, function($constraint){
            	 $constraint->upsize();	//this makes sure no upsize
            })->heighten(330, function($constraint){
            	 $constraint->upsize();	//this constraint makes sure no upsize
            });  
            $img->save(public_path().'/uploads/post/' . $new_filename);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment