示例#1
0
 public function __invoke($daemon)
 {
     error_log('checking gopro files');
     $imagine = $this->imagine;
     $new = [];
     foreach ($this->gopro->getFiles(GoPro::FILTER_PHOTO) as $file) {
         if (in_array($file->getSequence(), $this->list)) {
             continue;
         }
         $new[] = $file;
     }
     error_log('found files: ' . count($new));
     foreach ($new as $file) {
         error_log('downloading photo: ' . $file->getSequence());
         $content = $this->gopro->download($file);
         error_log('opening photo: ' . $file->getSequence());
         $photo = $imagine->load($content);
         error_log('resizing watermark');
         $watermark = $this->watermark->copy();
         $photoWidth = $photo->getSize();
         $waterSize = $watermark->getSize();
         $newSize = $waterSize->widen($photoWidth->getWidth() - 1);
         $watermark->resize($newSize);
         error_log('adding watermark');
         $pos = new Point(0, $photo->getSize()->getHeight() - $watermark->getSize()->getHeight());
         $photo->paste($watermark, $pos);
         error_log('uploading photo');
         $this->darkroom->upload($file, $photo->get('jpg'));
         error_log('resizing photo');
         $photo->resize(new Box($photo->getSize()->getWidth() / 4, $photo->getSize()->getHeight() / 4));
         error_log('uploading thumb');
         $this->darkroom->upload($file, $photo->get('jpg'), 'th');
         unset($photo);
         unset($watermark);
         $this->list[] = $file->getSequence();
     }
     if (!count($new)) {
         error_log('no new files, waiting a bit');
         sleep(60);
     }
     return true;
 }
示例#2
0
 /**
  * @param string $mark
  */
 protected function createMarkedMediaFile($mark)
 {
     $Media = $this->Media;
     \Yii::beginProfile(sprintf('create cache file: %s', $Media->id), __METHOD__);
     $this->imagine = Media\components\Image::getImagine()->open(\Yii::getAlias($Media->getAbsolutePath()));
     /** @var MediaModel $MediaModel */
     $MediaModel = \Yii::createObject(MediaModel::class);
     $mark_file_path = $this->getMarkedMediaPath($mark);
     $mark_dir = dirname($mark_file_path);
     if (!file_exists($mark_dir) || !is_dir($mark_dir)) {
         FileHelper::createDirectory($mark_dir, $MediaModel::getMediaModule()->pathChmod);
     }
     $Image = $this->imagine->copy();
     if (!empty($this->handlers)) {
         foreach ($this->handlers as $handler) {
             if (is_callable($handler)) {
                 $Image = $handler($Image);
             }
         }
     }
     $Image->save($mark_file_path, ['quality' => 90]);
     @chmod($mark_file_path, $MediaModel::getMediaModule()->fileChmod);
     \Yii::endProfile(sprintf('create cache file: %s', $Media->id), __METHOD__);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->copy();
 }
示例#4
0
 /**
  * Executes the actual resizing operation on the Imagine image.
  * In case of an outbound resize the image will be resized and cropped.
  *
  * @param ImagineImageInterface $image
  * @param string $mode
  * @param string $filter
  * @return \Imagine\Image\ManipulatorInterface
  */
 protected function resize(ImagineImageInterface $image, $mode = ImageInterface::RATIOMODE_INSET, $filter = ImagineImageInterface::FILTER_UNDEFINED)
 {
     if ($mode !== ImageInterface::RATIOMODE_INSET && $mode !== ImageInterface::RATIOMODE_OUTBOUND) {
         throw new \InvalidArgumentException('Invalid mode specified');
     }
     $imageSize = $image->getSize();
     $requestedDimensions = $this->calculateDimensions($imageSize);
     $resizedImage = $image->copy();
     $resizedImage->usePalette($image->palette());
     $resizedImage->strip();
     $resizeDimensions = $requestedDimensions;
     if ($mode === ImageInterface::RATIOMODE_OUTBOUND) {
         $resizeDimensions = $this->calculateOutboundScalingDimensions($imageSize, $requestedDimensions);
     }
     $resizedImage->resize($resizeDimensions, $filter);
     if ($mode === ImageInterface::RATIOMODE_OUTBOUND) {
         $resizedImage->crop(new Point(max(0, round(($resizeDimensions->getWidth() - $requestedDimensions->getWidth()) / 2)), max(0, round(($resizeDimensions->getHeight() - $requestedDimensions->getHeight()) / 2))), $requestedDimensions);
     }
     return $resizedImage;
 }
示例#5
0
 /**
  * Creates a thumbnail image. The function differs from `\Imagine\Image\ImageInterface::thumbnail()` function that
  * it keeps the aspect ratio of the image.
  * @param Imagine\Image\ImageInterface $Image the image
  * @param integer $width the width in pixels to create the thumbnail
  * @param integer $height the height in pixels to create the thumbnail
  * @param string $mode
  * @return \Imagine\Image\ImageInterface
  */
 public static function thumbnail($Image, $width, $height, $mode = Imagine\Image\ManipulatorInterface::THUMBNAIL_OUTBOUND)
 {
     $box = new Imagine\Image\Box($width, $height);
     $size = $Image->getSize();
     if ($size->getWidth() <= $box->getWidth() && $size->getHeight() <= $box->getHeight() || !$box->getWidth() && !$box->getHeight()) {
         return $Image->copy();
     }
     /** @var Imagine\Image\ImageInterface $Image */
     $Image = $Image->thumbnail($box, $mode);
     $Palette = new Imagine\Image\Palette\RGB();
     // create empty image to preserve aspect ratio of thumbnail
     $thumb = static::getImagine()->create($box, $Palette->color('#ffffff'));
     // calculate points
     $size = $Image->getSize();
     $startX = 0;
     $startY = 0;
     if ($size->getWidth() < $width) {
         $startX = ceil($width - $size->getWidth()) / 2;
     }
     if ($size->getHeight() < $height) {
         $startY = ceil($height - $size->getHeight()) / 2;
     }
     $thumb->paste($Image, new Imagine\Image\Point($startX, $startY));
     return $thumb;
 }