Created
February 21, 2023 04:31
-
-
Save AbiruzzamanMolla/7da3a3bac40ceafd6706be5a8a9342fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uploadImage(object $image, string $path = 'uploads/', int $width = null, int $height = null){ | |
if (!File::isDirectory($path)) { | |
File::makeDirectory($path, 0777, true, true); | |
} | |
$img = Image::make($image); | |
$img->resize($width, $height, function ($constraint) { | |
$constraint->aspectRatio(); | |
}); | |
$path = $path . Str::random(40) . '.' . $image->extension(); | |
$img->save($path); | |
return $path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment