Esempio n. 1
0
 public function ensureHasThumbnail()
 {
     if (!$this->thumb) {
         $ip = new ImageProcessor();
         $ip->makeUploadedImageThumbnail($this);
     }
 }
 /**
  * @param $userId
  *
  * @return Image
  */
 public static function getImage($userId)
 {
     $url = self::getUrl();
     $imageProcessor = new ImageProcessor();
     $filename = $imageProcessor->storeFromUrl($url, 'avatars');
     $image = new Image();
     $image->userId = $userId;
     $image->directory = 'avatars';
     $image->filename = $filename;
     $image->save();
     return $image->fresh();
 }
 /**
  * @api            {post} /images Upload An Image
  * @apiGroup       Images
  * @apiDescription Save an image.
  * @apiUse         RequiresAuthentication
  *
  * @param Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->requireAuthentication();
     $this->validate($request, ['file' => 'required|image']);
     $image = $request->file('file');
     $processor = new ImageProcessor($image);
     $filename = $processor->storeUserUploadedImage();
     $image = new Image(['userId' => $this->user->id, 'filename' => $filename]);
     $image->save();
     /** @var Image $image */
     $image = $image->fresh();
     return $this->response(['uploaded' => 1, 'filename' => $filename, 'url' => $image->getUrl(), 'image' => $image]);
 }