/** * Execute the console command. * * @return mixed */ public function handle() { foreach (config('uploader') as $bucket => $config) { if (isset($config['resize'])) { $disk = Storage::disk($config['disk']); $this->info('Processing ' . $bucket); foreach (Media::where('bucket', $bucket)->get() as $image) { $srcFile = $config['path'] . '/original/' . $image->fileName; $this->info('Source File ' . $srcFile); try { if (!$disk->has($srcFile)) { throw new Exception('File not found on source directory'); } foreach ($config['resize'] as $name => $size) { $temp = tempnam(storage_path('tmp'), 'tmp'); $file = $disk->get($srcFile); Image::make($file)->fit($size[0], $size[1])->save($temp); $destName = $config['path'] . '/' . $name . '/' . $image->fileName; $disk->put($destName, File::get($temp)); unlink($temp); $this->info(str_pad($name, 10) . ' >> ' . $destName); } } catch (Exception $e) { $this->error('Failed to process image. ERR:' . $e->getMessage()); } } } } }
public static function getMedia($id, $bucketName, $size) { $media = Media::where(['id' => $id, 'bucket' => $bucketName])->first(); if (is_null($media)) { return abort(404); } $bucket = Bucket::find($bucketName); $disk = Storage::disk($bucket->disk()); if ($disk->exists($bucket->path() . '/' . $size . '/' . $media->fileName)) { return response($disk->get($bucket->path() . '/' . $size . '/' . $media->fileName))->header('Content-type', $media->mime); } abort(404); }