Ejemplo n.º 1
0
 /**
  * Resize an image to an exact width and height.
  *
  * @param  UploadedFile $file
  * @param  string $width - The image's new width.
  * @param  string $height - The image's new height.
  * @return Imagine\Image
  */
 protected function resizeExact($file, $width, $height)
 {
     return $this->imagine->open($file->getRealPath())->resize(new Box($width, $height));
 }
Ejemplo n.º 2
0
 /**
  * Upload file to Amazon s3
  *
  * @param  UploadedFile $file
  * @param  String $subdirectory
  * @return Array $uploadedFile
  */
 private function s3Upload($file, $subdirectory)
 {
     $client_original_name = $file->getClientOriginalName();
     $fileName = time() . '_' . $client_original_name;
     $destinationPath = 'uploads/' . $subdirectory;
     $path = $destinationPath . '/' . $fileName;
     $image = Image::make($file->getRealPath());
     $image->resize(600, null, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     });
     $stream = $image->stream();
     $s3 = Storage::disk('s3');
     $s3->put($path, $stream->__toString(), 'public');
     $client = $s3->getDriver()->getAdapter()->getClient();
     $public_url = $client->getObjectUrl(env('S3_BUCKET'), $path);
     $original_name = pathinfo($client_original_name, PATHINFO_FILENAME);
     $uploadedFile = ['original_name' => $original_name, 'file_name' => $fileName, 'public_url' => $public_url];
     return $uploadedFile;
 }