Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AbiruzzamanMolla/7da3a3bac40ceafd6706be5a8a9342fa to your computer and use it in GitHub Desktop.
Save AbiruzzamanMolla/7da3a3bac40ceafd6706be5a8a9342fa to your computer and use it in GitHub Desktop.
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