コード例 #1
0
ファイル: Autorotate.php プロジェクト: ccq18/EduSoho
 private function getColor(ImageInterface $image)
 {
     if ($this->color instanceof ColorInterface) {
         return $this->color;
     }
     return $image->palette()->color($this->color);
 }
コード例 #2
0
 /**
  * Command image colorize
  * 
  * @param string $hexColor
  * 
  * @return void
  */
 protected function imageColorize($hexColor)
 {
     if (strlen($hexColor) != 6 || !preg_match('![0-9abcdef]!i', $hexColor)) {
         throw new BadMethodCallException('Invalid parameter color for command "colorize"');
     }
     $color = $this->image->palette()->color('#' . $hexColor);
     $this->image->effects()->colorize($color);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function load(ImageInterface $image, array $options = array())
 {
     $background = $image->palette()->color(isset($options['color']) ? $options['color'] : '#fff', isset($options['transparency']) ? $options['transparency'] : null);
     $topLeft = new Point(0, 0);
     $size = $image->getSize();
     if (isset($options['size'])) {
         list($width, $height) = $options['size'];
         $position = isset($options['position']) ? $options['position'] : 'center';
         switch ($position) {
             case 'topleft':
                 $x = 0;
                 $y = 0;
                 break;
             case 'top':
                 $x = ($width - $image->getSize()->getWidth()) / 2;
                 $y = 0;
                 break;
             case 'topright':
                 $x = $width - $image->getSize()->getWidth();
                 $y = 0;
                 break;
             case 'left':
                 $x = 0;
                 $y = ($height - $image->getSize()->getHeight()) / 2;
                 break;
             case 'center':
                 $x = ($width - $image->getSize()->getWidth()) / 2;
                 $y = ($height - $image->getSize()->getHeight()) / 2;
                 break;
             case 'right':
                 $x = $width - $image->getSize()->getWidth();
                 $y = ($height - $image->getSize()->getHeight()) / 2;
                 break;
             case 'bottomleft':
                 $x = 0;
                 $y = $height - $image->getSize()->getHeight();
                 break;
             case 'bottom':
                 $x = ($width - $image->getSize()->getWidth()) / 2;
                 $y = $height - $image->getSize()->getHeight();
                 break;
             case 'bottomright':
                 $x = $width - $image->getSize()->getWidth();
                 $y = $height - $image->getSize()->getHeight();
                 break;
             default:
                 throw new \InvalidArgumentException("Unexpected position '{$position}'");
                 break;
         }
         $size = new Box($width, $height);
         $topLeft = new Point($x, $y);
     }
     $canvas = $this->imagine->create($size, $background);
     return $canvas->paste($image, $topLeft);
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function load(ImageInterface $image, array $options = array())
 {
     $background = $image->palette()->color(isset($options['color']) ? $options['color'] : '#fff', isset($options['transparency']) ? $options['transparency'] : null);
     $topLeft = new Point(0, 0);
     $size = $image->getSize();
     if (isset($options['size'])) {
         list($width, $height) = $options['size'];
         $size = new Box($width, $height);
         $topLeft = new Point(($width - $image->getSize()->getWidth()) / 2, ($height - $image->getSize()->getHeight()) / 2);
     }
     $canvas = $this->imagine->create($size, $background);
     return $canvas->paste($image, $topLeft);
 }
コード例 #5
0
 /**
  * {@inheritDoc}
  */
 public function apply(ImageInterface $image)
 {
     if ($this->size) {
         list($width, $height) = $this->size;
         $size = new Box($width, $height);
         $topLeft = new Point(($width - $image->getSize()->getWidth()) / 2, ($height - $image->getSize()->getHeight()) / 2);
     } else {
         $topLeft = new Point(0, 0);
         $size = $image->getSize();
     }
     $background = $image->palette()->color($this->color);
     $canvas = $this->imagine->create($size, $background);
     return $canvas->paste($image, $topLeft);
 }
コード例 #6
0
 public function load(ImageInterface $image, array $options = array())
 {
     $optionsCount = count($options);
     if ($optionsCount < 2) {
         throw new InvalidArgumentException('Invalid options for border filter. You must provide array(width, height)');
     }
     $color = static::DEFAULT_BORDER_COLOR;
     if ($optionsCount > 2) {
         list($width, $height, $color) = $options;
     } else {
         list($width, $height) = $options;
     }
     $border = new Border($image->palette()->color($color), $width, $height);
     return $border->apply($image);
 }
コード例 #7
0
 /**
  * Draw centered text in current image
  * 
  * @param string $text
  * @param string $color
  * 
  * @return void
  */
 protected function drawCenteredText($text, $color)
 {
     $width = $this->image->getSize()->getWidth();
     $height = $this->image->getSize()->getHeight();
     $fontColor = $this->image->palette()->color('#' . $color);
     $fontSize = 48;
     $widthFactor = $width > 160 ? 0.8 : 0.9;
     $heightFactor = $height > 160 ? 0.8 : 0.9;
     do {
         $font = $this->getImagineService()->font(__DIR__ . '/../../../data/font/Roboto-Regular.ttf', $fontSize, $fontColor);
         $fontBox = $font->box($text);
         $fontSize = round($fontSize * 0.8);
     } while ($fontSize > 5 && ($width * $widthFactor < $fontBox->getWidth() || $height * $heightFactor < $fontBox->getHeight()));
     $pointX = max(0, floor(($width - $fontBox->getWidth()) / 2));
     $pointY = max(0, floor(($height - $fontBox->getHeight()) / 2));
     $this->image->draw()->text($text, $font, new Point($pointX, $pointY));
 }
コード例 #8
0
ファイル: MainPage.php プロジェクト: andrei2nikitin/quiz
 /**
  * Применяет эффект к изображению.
  * @param ImageInterface $Image
  * @param string $effect
  * @param string $additional
  * @return bool
  */
 private function applyEffect(ImageInterface $Image, $effect, $additional = null)
 {
     switch ($effect) {
         case 'resize':
             if (!isset($additional['width']) || !isset($additional['height'])) {
                 return false;
             }
             $Image->resize(new Box($additional['width'], $additional['height']));
             break;
         case 'origin':
             break;
         case 'negative':
             $Image->effects()->negative();
             break;
         case 'grayscale':
             $Image->effects()->grayscale();
             break;
         case 'sharpen':
             $Image->effects()->sharpen();
             break;
         case 'colorize':
             $Image->effects()->colorize($Image->palette()->color($additional));
             break;
         case 'gamma':
             $Image->effects()->gamma($additional);
             break;
         case 'blur':
             $Image->effects()->blur($additional);
             break;
         default:
             return false;
     }
     return true;
 }
コード例 #9
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;
 }
コード例 #10
0
 /**
  * Apply colorize filter
  *
  * @param  ImageInterface	$image An image instance
  * @param  string			$color The hex value of the color
  * @return void
  */
 protected function filterColorize(ImageInterface $image, $color)
 {
     $color = $image->palette()->color($color);
     $image->effects()->colorize($color);
     return $image;
 }
コード例 #11
0
 /**
  * @param \Imagine\Image\ImageInterface $image
  * @param array $options
  * @return \Imagine\Image\ImageInterface
  */
 protected function applyColorizeFilter(ImageInterface $image, $options)
 {
     if (isset($options['color'])) {
         $color = $image->palette()->color($options['color']);
         $image->effects()->colorize($color);
     }
     return $image;
 }
コード例 #12
0
 /**
  * Применяет эффект к изображению.
  * @param ImageInterface $Image
  * @param string $effect
  * @param string $additional
  * @return bool
  */
 private function applyEffect(ImageInterface $Image, $effect, $additional = null)
 {
     switch ($effect) {
         case 'origin':
             break;
         case 'negative':
             $Image->effects()->negative();
             break;
         case 'grayscale':
             $Image->effects()->grayscale();
             break;
         case 'sharpen':
             $Image->effects()->sharpen();
             break;
         case 'colorize':
             $Image->effects()->colorize($Image->palette()->color($additional));
             break;
         case 'gamma':
             $Image->effects()->gamma($additional);
             break;
         case 'blur':
             $Image->effects()->blur($additional);
             break;
         default:
             return false;
     }
     return true;
 }
コード例 #13
0
ファイル: ImagineImageConverter.php プロジェクト: sulu/sulu
 /**
  * Ensures that the color mode of the passed image is RGB.
  *
  * @param ImageInterface $image
  *
  * @return ImageInterface $image The modified image
  */
 private function toRGB(ImageInterface $image)
 {
     if ($image->palette()->name() == 'cmyk') {
         $image->usePalette(new RGB());
     }
     return $image;
 }