示例#1
0
 /**
  * @param MediaRepositoryInterface $media
  * @param ImageManager $images
  * @param Filesystem $files
  * @return bool
  * @throws Exception
  */
 public function handle(MediaRepositoryInterface $media, ImageManager $images, Filesystem $files)
 {
     list($width, $height) = $this->dimensions($this->size);
     $path = $this->getPath($files);
     $constraint = $this->constraint($width, $height);
     $image = $images->cache(function ($image) use($width, $height, $constraint) {
         if ($this->cachedPath) {
             $image = $image->make($this->cachedPath);
         } else {
             $image = $image->make(public_path($this->image->path));
         }
         $image->resize($width, $height, $constraint);
     }, 60, true)->save($path);
     if ($image) {
         //always fetch the actual width and height from the image,
         //one of them could have been null to auto scale the image.
         $width = $image->getWidth();
         $height = $image->getHeight();
         //use html public path to store in database
         $path = $this->getPath($files, true);
         try {
             $media->createThumbnailImage($this->getPayload($width, $height, $path), $this->image);
         } catch (Exception $e) {
             $files->delete(public_path($path));
             unset($image);
             return false;
         }
         unset($image);
     }
 }
示例#2
0
 /**
  * @param AccountManager $accounts
  * @param MediaRepositoryInterface $media
  * @param Locale $locale
  * @return bool
  */
 public function handle(AccountManager $accounts, MediaRepositoryInterface $media, Locale $locale)
 {
     if ($this->input['mode'] == 'youtube') {
         $info = $this->handleYoutube();
     } elseif ($this->input['mode'] == 'vimeo') {
         $info = $this->handleVimeo();
     }
     if (!$info) {
         return false;
     }
     $locale = $locale->whereSlug($this->input['locale'])->firstOrFail();
     $input = array_merge(array_except($this->input, ['url', 'mode']), ['provider' => $this->input['mode'], 'provider_id' => $info['provider_id'], 'provider_thumbnail' => $info['provider_thumbnail'], 'title' => $info['title'], 'description' => $info['description'], 'width' => $info['width'], 'height' => $info['height'], 'account_id' => $accounts->account()->id, 'locale_id' => $locale->id]);
     return $media->createVideo($this->owner, $input);
 }
示例#3
0
 /**
  * @param MediaRepositoryInterface $repo
  * @param Filesystem $files
  * @param Configurator $config
  * @return bool
  */
 public function handle(MediaRepositoryInterface $repo, Filesystem $files, Configurator $config)
 {
     if (!$files->exists($this->currentPath)) {
         return false;
     }
     $this->newName();
     $this->handleFile($files, $config);
     try {
         return $repo->createFile($this->owner, $this->getPayload());
     } catch (Exception $exception) {
         //probably duplicate file error, always remove created file on error.
         $files->delete(public_path($this->path));
         return false;
     }
 }
示例#4
0
 /**
  * @param MediaRepositoryInterface $repo
  * @param ImageManager $images
  * @param Filesystem $files
  * @param Configurator $config
  * @return bool
  */
 public function handle(MediaRepositoryInterface $repo, ImageManager $images, Filesystem $files, Configurator $config)
 {
     if (!$files->exists($this->currentPath)) {
         return false;
     }
     $this->dimensions($images);
     $this->newName();
     $this->handleFile($files, $config);
     try {
         $image = $repo->createImage($this->owner, $this->getPayload());
     } catch (Exception $e) {
         $files->delete(public_path($this->path));
         return false;
     }
     if ($image) {
         foreach ($config->getImageSizes($this->owner) as $size) {
             $this->dispatch(new ResizeImage($image, $size, $this->currentPath));
         }
         return $image;
     }
     return false;
 }