format('Y/m/d'); $path = "uploads/{$type}/thumbs/{$folder}"; if (!file_exists(public_path($path))) { mkdir(public_path($path), 0775, true); } return $path; } /** * @param $path * @param $size * @param $type * @return string */ public function resize($path, $size, $type) { $name = basename($path); $folder = $this->mkdir($type); $path_thumb = "{$folder}/{$name}"; if (env('FILESYSTEM_DISK') == 's3') { try{ $file = Storage::disk("public")->get($path); }catch(Exception $e){ $file = file_get_contents($path); } $img = Imagee::make($file); $img->resize($size, null, function ($constraint) { $constraint->aspectRatio(); }); // delete temp file $img->save("{$path_thumb}", 100); Storage::disk('s3')->put($path_thumb, file_get_contents($path_thumb)); } else { // source can be in storage/app/public (from ->store('temp','public')) or public/ $srcPath = file_exists(public_path($path)) ? public_path($path) : storage_path('app/public/' . $path); $img = Imagee::make($srcPath); $img->resize($size, null, function ($constraint) { $constraint->aspectRatio(); }); $img->save(public_path($path_thumb), 100); } return $path_thumb; } }