当前位置: 首页>>代码示例>>PHP>>正文


PHP ImageInterface::paste方法代码示例

本文整理汇总了PHP中Imagine\Image\ImageInterface::paste方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageInterface::paste方法的具体用法?PHP ImageInterface::paste怎么用?PHP ImageInterface::paste使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Imagine\Image\ImageInterface的用法示例。


在下文中一共展示了ImageInterface::paste方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * {@inheritdoc}
  */
 public function execute(ImageInterface $image, $parameters)
 {
     $maskPath = isset($parameters['image']) ? $this->fileLocator->locate($parameters['image']) : null;
     if (!$maskPath) {
         return $image;
     }
     $originalWidth = $image->getSize()->getWidth();
     $originalHeight = $image->getSize()->getHeight();
     $top = isset($parameters['top']) ? $parameters['top'] : 0;
     $left = isset($parameters['left']) ? $parameters['left'] : 0;
     $width = isset($parameters['width']) ? $parameters['width'] : $originalWidth;
     $height = isset($parameters['height']) ? $parameters['height'] : $originalHeight;
     // imagine will error when mask is bigger then the given image
     // this could happen in forceRatio true mode so we need also scale the mask
     if ($width > $originalWidth) {
         $width = $originalWidth;
         $height = (int) ($height / $width * $originalWidth);
     }
     if ($height > $originalHeight) {
         $height = $originalHeight;
         $width = (int) ($width / $height * $originalHeight);
     }
     // create mask
     $mask = $this->createMask($maskPath, $width, $height);
     // add mask to image
     $image->paste($mask, new Point($top, $left));
     return $image;
 }
开发者ID:sulu,项目名称:sulu,代码行数:31,代码来源:PasteTransformation.php

示例2: apply

 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     $watermark = $this->imagine->open($this->watermarkFilename);
     $size = $image->getSize();
     $wSize = $watermark->getSize();
     // Watermark in top left
     $topLeftPoint = new Point(self::WATERMARK_PADDING, self::WATERMARK_PADDING);
     $image->paste($watermark, $topLeftPoint);
     // Watermark in bottom right
     $bottomRightPoint = new Point($size->getWidth() - $wSize->getWidth() - self::WATERMARK_PADDING, $size->getHeight() - $wSize->getHeight() - self::WATERMARK_PADDING);
     $image->paste($watermark, $bottomRightPoint);
     // Watermark in middle
     $middlePoint = new Point(floor($size->getWidth() / 2 - $wSize->getWidth() / 2), floor($size->getHeight() / 2 - $wSize->getHeight() / 2));
     $image->paste($watermark, $middlePoint);
     return $image;
 }
开发者ID:kuzmina-mariya,项目名称:4seasons,代码行数:19,代码来源:Watermark.php

示例3: drawImage

 /**
  * Draw $image on $this->resultImage.
  *
  * @param string $image Image blob.
  * @param Point  $point The point where to draw $image.
  *
  * @return void
  */
 protected function drawImage($image, Point $point)
 {
     try {
         $this->resultImage->paste($this->imagine->load($image), $point);
     } catch (\Exception $exception) {
         // Most likely an exception about a out of bounds past, we'll just ignore that
     }
 }
开发者ID:wyrihaximus,项目名称:staticmap,代码行数:16,代码来源:Renderer.php

示例4: pasteCentered

 protected function pasteCentered(\Imagine\Image\ImageInterface $image, \Imagine\Image\ImageInterface $original)
 {
     $originalSize = $original->getSize();
     $x = $this->getPasteValue($this->size->getWidth(), $originalSize->getWidth());
     $y = $this->getPasteValue($this->size->getHeight(), $originalSize->getHeight());
     $pastePoint = new \Imagine\Image\Point($x, $y);
     $image->paste($original, $pastePoint);
     return $image;
 }
开发者ID:rtablada,项目名称:resize-and-pad,代码行数:9,代码来源:ResizeAndPad.php

示例5: watermark

 /**
  * Adds a watermark to an existing image.
  * @param string $watermarkFilename the file path or path alias of the watermark image.
  * @param array $start the starting point. This must be an array with two elements representing `x` and `y` coordinates.
  * @return static
  * @throws InvalidParamException if `$start` is invalid
  */
 public function watermark($watermarkFilename, array $start = [0, 0])
 {
     if (!isset($start[0], $start[1])) {
         throw new InvalidParamException('$start must be an array of two elements.');
     }
     $watermark = static::getImagine()->open(Yii::getAlias($watermarkFilename));
     $this->image->paste($watermark, new Point($start[0], $start[1]));
     return $this;
 }
开发者ID:maddoger,项目名称:yii2-imagecache,代码行数:16,代码来源:Image.php

示例6: addWatermark

 /**
  * Add a watermark to image. If no position is entered the watermark will be centered.
  *
  * @param $source
  * @param null $x
  * @param null $y
  * @return $this
  */
 public function addWatermark($source, $x = null, $y = null)
 {
     $watermark = $this->imagine->open($source);
     $wSize = $watermark->getSize();
     if (!$x && !$y) {
         $x = $this->openImage()->image->getSize()->getWidth() / 2 + $wSize->getWidth() / 2 - $wSize->getWidth();
         $y = $this->openImage()->image->getSize()->getHeight() / 2 + $wSize->getHeight() / 2 - $wSize->getHeight();
     }
     $position = new \Imagine\Image\Point($x, $y);
     $this->image = $this->image->paste($watermark, $position);
     return $this;
 }
开发者ID:fraym,项目名称:core,代码行数:20,代码来源:Editor.php

示例7: load

 /**
  * @see Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface::load()
  */
 public function load(ImageInterface $image, array $options = array())
 {
     list($x, $y) = $options['start'];
     $destImage = $this->imagine->open($this->rootPath . '/' . $options['image']);
     return $image->paste($destImage, new Point($x, $y));
 }
开发者ID:umanit,项目名称:LiipImagineBundle,代码行数:9,代码来源:PasteFilterLoader.php

示例8: apply

 /**
  * (non-PHPdoc)
  * @see Imagine\Filter\FilterInterface::apply()
  */
 public function apply(ImageInterface $image)
 {
     return $image->paste($this->image, $this->start);
 }
开发者ID:SerdarSanri,项目名称:laravel-imagine-bundle,代码行数:8,代码来源:Paste.php

示例9: apply

 /**
  * {@inheritDoc}
  */
 public function apply(ImageInterface $image)
 {
     $watermark = $this->watermark;
     $size = $image->getSize();
     $watermarkSize = $watermark->getSize();
     // If 'null': Downscale if needed
     if (!$this->size && ($size->getWidth() < $watermarkSize->getWidth() || $size->getHeight() < $watermarkSize->getHeight())) {
         $this->size = 1.0;
     }
     if ($this->size) {
         $factor = $this->size * min($size->getWidth() / $watermarkSize->getWidth(), $size->getHeight() / $watermarkSize->getHeight());
         $watermark->resize(new Box($watermarkSize->getWidth() * $factor, $watermarkSize->getHeight() * $factor));
         $watermarkSize = $watermark->getSize();
     }
     switch ($this->position) {
         case 'topleft':
             $x = 0;
             $y = 0;
             break;
         case 'top':
             $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
             $y = 0;
             break;
         case 'topright':
             $x = $size->getWidth() - $watermarkSize->getWidth();
             $y = 0;
             break;
         case 'left':
             $x = 0;
             $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
             break;
         case 'center':
             $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
             $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
             break;
         case 'right':
             $x = $size->getWidth() - $watermarkSize->getWidth();
             $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
             break;
         case 'bottomleft':
             $x = 0;
             $y = $size->getHeight() - $watermarkSize->getHeight();
             break;
         case 'bottom':
             $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
             $y = $size->getHeight() - $watermarkSize->getHeight();
             break;
         case 'bottomright':
             $x = $size->getWidth() - $watermarkSize->getWidth();
             $y = $size->getHeight() - $watermarkSize->getHeight();
             break;
         default:
             throw new Exception\InvalidArgumentException(sprintf('Unknown position "%s"', $this->position));
     }
     return $image->paste($watermark, new Point($x, $y));
 }
开发者ID:shitikovkirill,项目名称:zend-shop.com,代码行数:59,代码来源:Watermark.php

示例10: load

 /**
  * @see Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface::load()
  */
 public function load(ImageInterface $image, array $options = array())
 {
     $options += array('size' => null, 'position' => 'center');
     if (substr($options['size'], -1) == '%') {
         $options['size'] = substr($options['size'], 0, -1) / 100;
     }
     $watermark = $this->imagine->open($this->rootPath . '/' . $options['image']);
     $size = $image->getSize();
     $watermarkSize = $watermark->getSize();
     // If 'null': Downscale if needed
     if (!$options['size'] && ($size->getWidth() < $watermarkSize->getWidth() || $size->getHeight() < $watermarkSize->getHeight())) {
         $options['size'] = 1.0;
     }
     if ($options['size']) {
         $factor = $options['size'] * min($size->getWidth() / $watermarkSize->getWidth(), $size->getHeight() / $watermarkSize->getHeight());
         $watermark->resize(new Box($watermarkSize->getWidth() * $factor, $watermarkSize->getHeight() * $factor));
         $watermarkSize = $watermark->getSize();
     }
     switch ($options['position']) {
         case 'topleft':
             $x = 0;
             $y = 0;
             break;
         case 'top':
             $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
             $y = 0;
             break;
         case 'topright':
             $x = $size->getWidth() - $watermarkSize->getWidth();
             $y = 0;
             break;
         case 'left':
             $x = 0;
             $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
             break;
         case 'center':
             $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
             $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
             break;
         case 'right':
             $x = $size->getWidth() - $watermarkSize->getWidth();
             $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
             break;
         case 'bottomleft':
             $x = 0;
             $y = $size->getHeight() - $watermarkSize->getHeight();
             break;
         case 'bottom':
             $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
             $y = $size->getHeight() - $watermarkSize->getHeight();
             break;
         case 'bottomright':
             $x = $size->getWidth() - $watermarkSize->getWidth();
             $y = $size->getHeight() - $watermarkSize->getHeight();
             break;
         default:
             throw new \InvalidArgumentException("Unexpected position '{$options['position']}'");
             break;
     }
     return $image->paste($watermark, new Point($x, $y));
 }
开发者ID:sanchojaf,项目名称:oldmytriptocuba,代码行数:64,代码来源:WatermarkFilterLoader.php

示例11: transform

 public function transform(ImageInterface $image, ImagineInterface $imagine)
 {
     if (!isset($this->path)) {
         throw new InvalidConfigException(sprintf('Path to the watermark file must be specified in %s::$path.', self::className()));
     }
     $this->imageWidth = $image->getSize()->getWidth();
     $this->imageHeight = $image->getSize()->getHeight();
     $watermarkImageMaxWidth = $this->imageWidth - 2 * $this->margin;
     if ($watermarkImageMaxWidth < 1) {
         return;
     }
     $watermarkImageMaxHeight = $this->imageHeight - 2 * $this->margin;
     if ($watermarkImageMaxHeight < 1) {
         return;
     }
     $watermarkImage = $imagine->open(\Yii::getAlias($this->path));
     if (!(new Box($watermarkImageMaxWidth, $watermarkImageMaxHeight))->contains($watermarkImage->getSize())) {
         $resize = new Resize();
         $resize->width = $watermarkImageMaxWidth;
         $resize->height = $watermarkImageMaxHeight;
         $resize->scaleTo = 'fit';
         $resize->transform($watermarkImage, $imagine);
     }
     $this->watermarkImageWidth = $watermarkImage->getSize()->getWidth();
     $this->watermarkImageHeight = $watermarkImage->getSize()->getHeight();
     switch ($this->align) {
         case 'top-left':
             $start = new Point($this->getStartXLeft(), $this->getStarYTop());
             break;
         case 'top-center':
             $start = new Point($this->getStartXCenter(), $this->getStarYTop());
             break;
         case 'top-right':
             $start = new Point($this->getStartXRight(), $this->getStarYTop());
             break;
         case 'bottom-left':
             $start = new Point($this->getStartXLeft(), $this->getStartYBottom());
             break;
         case 'bottom-center':
             $start = new Point($this->getStartXCenter(), $this->getStartYBottom());
             break;
         case 'bottom-right':
             $start = new Point($this->getStartXRight(), $this->getStartYBottom());
             break;
         case 'center':
             $start = new Point($this->getStartXCenter(), $this->getStartYCenter());
             break;
         default:
             throw new InvalidConfigException(sprintf('Invalid value for property "align": %s.', is_scalar($this->align) ? $this->align : gettype($this->align)));
     }
     $image->paste($watermarkImage, $start);
 }
开发者ID:phtamas,项目名称:yii2-imageprocessor,代码行数:52,代码来源:Watermark.php

示例12: applyWatermark

 /**
  * Applies watermark to image.
  *
  * @param ImageInterface   $image
  * @param ImageInterface $watermark
  *
  * @return ImageInterface
  */
 private function applyWatermark(ImageInterface $image, ImageInterface $watermark)
 {
     $size = $image->getSize();
     $wSize = $watermark->getSize();
     $bottomRight = new Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight());
     $image->paste($watermark, $bottomRight);
     return $image;
 }
开发者ID:Zylius,项目名称:GalerijaAPI,代码行数:16,代码来源:ImageManipulationService.php

示例13: pasteImage

 private function pasteImage(ImageInterface $image, ImageInterface $imageToPaste, PointInterface $pastePoint)
 {
     if (!$this->boxContains($image->getSize(), $imageToPaste->getSize(), $pastePoint)) {
         $rectangle = Rectangle::createWithSize($image->getSize())->intersection(Rectangle::create($pastePoint, $imageToPaste->getSize()));
         if ($rectangle !== null) {
             $croppingPoint = new Point($rectangle->getStartingPoint()->getX() - $pastePoint->getX(), $rectangle->getStartingPoint()->getY() - $pastePoint->getY());
             $imageToPaste->crop($croppingPoint, $rectangle->getSize());
             $image->paste($imageToPaste, $this->ensureNonNegativePoint($pastePoint));
         }
     } else {
         $image->paste($imageToPaste, $pastePoint);
     }
 }
开发者ID:zhangxiaoliu,项目名称:PHPPdf,代码行数:13,代码来源:GraphicsContext.php


注:本文中的Imagine\Image\ImageInterface::paste方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。