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


PHP ImageInterface::crop方法代码示例

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


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

示例1: cropImage

 /**
  * Crop image if exceeds boundaries
  *
  * @param ImageInterface $image
  * @param $settings
  * @return ImageInterface
  */
 private function cropImage(ImageInterface $image, $settings)
 {
     $neededSize = new Box($settings['width'], $settings['height']);
     $currentSize = $image->getSize();
     if ($neededSize->contains($currentSize)) {
         return $image;
     }
     $point = new Point($currentSize->getWidth() > $neededSize->getWidth() ? round(($currentSize->getWidth() - $neededSize->getWidth()) / 2) : 0, $currentSize->getHeight() > $neededSize->getHeight() ? round(($currentSize->getHeight() - $neededSize->getHeight()) / 2) : 0);
     $image->crop($point, $neededSize);
     return $image;
 }
开发者ID:xaben,项目名称:XabenMediaBundle,代码行数:18,代码来源:OutboundResizer.php

示例2: crop

 /**
  * {@inheritdoc}
  */
 public function crop(ImageInterface $image, $x, $y, $width, $height)
 {
     $point = new Point($x, $y);
     $box = new Box($width, $height);
     $image->crop($point, $box);
     return $image;
 }
开发者ID:sulu,项目名称:sulu,代码行数:10,代码来源:Cropper.php

示例3: generate

 /**
  * Generate the static map image and add blips to it if any are found
  *
  * @return ImageInterface The resulting image
  *
  * @return void
  */
 public function generate()
 {
     $box = Geo::calculateBox($this->size, $this->centerPoint);
     $this->resultImage = $this->imagine->create($box['base']);
     $jj = 0;
     $xStart = $box['tiles']['start']->getX();
     $xStop = $box['tiles']['stop']->getX();
     $yStart = $box['tiles']['start']->getY();
     $yStop = $box['tiles']['stop']->getY();
     for ($i = $yStart - 1; $i < $yStop; $i++) {
         $ii = 0;
         for ($j = $xStart - 1; $j < $xStop; $j++) {
             $this->addTile($this->tiles->getTile($j, $i), new Point($ii * Geo::TILE_SIZE, $jj * Geo::TILE_SIZE));
             $ii++;
         }
         $jj++;
     }
     $this->loader->run();
     $this->resultImage->crop($box['crop'], $this->size);
     foreach ($this->blips as $blip) {
         $this->drawBlip($blip);
     }
     $this->loader->run();
     return $this->resultImage;
 }
开发者ID:wyrihaximus,项目名称:staticmap,代码行数:32,代码来源:Renderer.php

示例4: crop

	/**
	 * Crops the image to the specified coordinates.
	 *
	 * @param int $x1
	 * @param int $x2
	 * @param int $y1
	 * @param int $y2
	 *
	 * @return Image
	 */
	public function crop($x1, $x2, $y1, $y2)
	{
		$width = $x2 - $x1;
		$height = $y2 - $y1;

		if ($this->_isAnimatedGif)
		{

			// Create a new image instance to avoid object references messing up our dimensions.
			$newSize = new \Imagine\Image\Box($width, $height);
			$startingPoint = new \Imagine\Image\Point($x1, $y1);
			$gif = $this->_instance->create($newSize);
			$gif->layers()->remove(0);

			foreach ($this->_image->layers() as $layer)
			{
				$croppedLayer = $layer->crop($startingPoint, $newSize);
				$gif->layers()->add($croppedLayer);
			}

			$this->_image = $gif;
		}
		else
		{
			$this->_image->crop(new \Imagine\Image\Point($x1, $y1), new \Imagine\Image\Box($width, $height));
		}

		return $this;
	}
开发者ID:harish94,项目名称:Craft-Release,代码行数:39,代码来源:Image.php

示例5: crop

 /**
  * Crops the image to the specified coordinates.
  *
  * @param int $x1
  * @param int $x2
  * @param int $y1
  * @param int $y2
  *
  * @return Image
  */
 public function crop($x1, $x2, $y1, $y2)
 {
     $width = $x2 - $x1;
     $height = $y2 - $y1;
     if ($this->_isAnimatedGif) {
         $this->_image->layers()->coalesce();
         // Create a new image instance to avoid object references messing up our dimensions.
         $newSize = new \Imagine\Image\Box($width, $height);
         $startingPoint = new \Imagine\Image\Point($x1, $y1);
         $gif = $this->_instance->create($newSize);
         $gif->layers()->remove(0);
         foreach ($this->_image->layers() as $layer) {
             $croppedLayer = $layer->crop($startingPoint, $newSize);
             $gif->layers()->add($croppedLayer);
             // Let's update dateUpdated in case this is going to take awhile.
             if ($index = craft()->assetTransforms->getActiveTransformIndexModel()) {
                 craft()->assetTransforms->storeTransformIndexData($index);
             }
         }
         $this->_image = $gif;
     } else {
         $this->_image->crop(new \Imagine\Image\Point($x1, $y1), new \Imagine\Image\Box($width, $height));
     }
     return $this;
 }
开发者ID:vescoyez,项目名称:portfolio_v2,代码行数:35,代码来源:Image.php

示例6: crop

 /**
  * Crops an image.
  *
  * ~~~
  *
  * @param integer $width the crop width
  * @param integer $height the crop height
  * @param array $start the starting point. This must be an array with two elements representing `x` and `y` coordinates.
  * @return ImageInterface
  * @throws InvalidParamException if the `$start` parameter is invalid
  */
 public function crop($width, $height, array $start = [0, 0])
 {
     if (!isset($start[0], $start[1])) {
         throw new InvalidParamException('$start must be an array of two elements.');
     }
     $this->image->crop(new Point($start[0], $start[1]), new Box($width, $height));
     return $this;
 }
开发者ID:maddoger,项目名称:yii2-imagecache,代码行数:19,代码来源:Image.php

示例7: execute

 /**
  * {@inheritdoc}
  */
 public function execute(ImageInterface &$image, $parameters)
 {
     $retina = isset($parameters['retina']) && $parameters['retina'] != 'false' ? 2 : 1;
     $x = isset($parameters['x']) ? intval($parameters['x']) * $retina : 0;
     $y = isset($parameters['y']) ? intval($parameters['y']) * $retina : 0;
     $width = isset($parameters['w']) ? intval($parameters['w']) : 0;
     $height = isset($parameters['h']) ? intval($parameters['h']) : 0;
     $point = new Point($x, $y);
     $box = new Box($width, $height);
     $image->crop($point, $box);
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:14,代码来源:CropCommand.php

示例8: performResize

 /**
  * Performs resize of the image. Imagine component is used.
  *
  * @param ImageInterface $imagine
  * @param                $resize
  * @param bool           $crop
  *
  * @return BoxInterface
  */
 private function performResize($imagine, $resize, $crop = true)
 {
     $box = $imagine->getSize();
     list($width, $height) = Utils::getDimension($resize);
     $box = $box->scale(max($width / $box->getWidth(), $height / $box->getHeight()));
     $imagine->resize($box);
     if ($crop) {
         $point = new Point(($box->getWidth() - $width) / 2, ($box->getHeight() - $height) / 2);
         $imagine->crop($point, new Box($width, $height));
     }
     return $box;
 }
开发者ID:voodoo-mobile,项目名称:yii2-image,代码行数:21,代码来源:UploadedImage.php

示例9: execute

 /**
  * {@inheritdoc}
  */
 public function execute(ImageInterface $image, $parameters)
 {
     @trigger_error('CropTransformation is deprecated since version 1.4. Use the scale config instead', E_USER_DEPRECATED);
     $retina = isset($parameters['retina']) && $parameters['retina'] != 'false' ? 2 : 1;
     $x = isset($parameters['x']) ? intval($parameters['x']) * $retina : 0;
     $y = isset($parameters['y']) ? intval($parameters['y']) * $retina : 0;
     $width = isset($parameters['w']) ? intval($parameters['w']) : 0;
     $height = isset($parameters['h']) ? intval($parameters['h']) : 0;
     $point = new Point($x, $y);
     $box = new Box($width, $height);
     $image->crop($point, $box);
     return $image;
 }
开发者ID:sulu,项目名称:sulu,代码行数:16,代码来源:CropTransformation.php

示例10: transform

 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function transform(ImageInterface $image, ImagineInterface $imagine)
 {
     $this->imageWidth = $image->getSize()->getWidth();
     $this->imageHeight = $image->getSize()->getHeight();
     $x = $this->parseX($this->x);
     $y = $this->parseY($this->y);
     $width = $this->width;
     $height = $this->height;
     if ($x + $width > $image->getSize()->getWidth()) {
         $width -= $x + $width - $image->getSize()->getWidth();
     }
     if ($y + $height > $image->getSize()->getHeight()) {
         $height -= $y + $height - $image->getSize()->getHeight();
     }
     $image->crop(new Point($x, $y), new Box($width, $height));
 }
开发者ID:phtamas,项目名称:yii2-imageprocessor,代码行数:19,代码来源:Crop.php

示例11: resize

 /**
  * resizes image using a focal point
  * @param  ImageInterface $image  an Imagine image
  * @param  BoxInterface   $size   size of resized imaga
  * @param  FocalPoint     $focal  focal point to use for size
  * @param  string         $filter Imagine filter to use
  * @return ImageInterface resized image
  */
 public function resize(ImageInterface $image, BoxInterface $size, FocalPointInterface $focal, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     $origSize = $image->getSize();
     $origWidth = $origSize->getWidth();
     $origHeight = $origSize->getHeight();
     $width = $size->getWidth();
     $height = $size->getHeight();
     $ratioHeight = $origHeight / $height;
     $ratioWidth = $origWidth / $width;
     if ($ratioHeight < $ratioWidth) {
         list($cropX1, $cropX2) = $this->calculateCrop($origWidth, $width, $focal->getX(), $ratioHeight);
         $cropY1 = 0;
         $cropY2 = $origHeight;
     } else {
         list($cropY1, $cropY2) = $this->calculateCrop($origHeight, $height, -$focal->getY(), $ratioWidth);
         $cropX1 = 0;
         $cropX2 = $origWidth;
     }
     $image->crop(new Point($cropX1, $cropY1), new Box($cropX2 - $cropX1, $cropY2 - $cropY1))->resize(new Box($width, $height, $filter));
     return $image;
 }
开发者ID:maagi,项目名称:imagine-focalresizer,代码行数:29,代码来源:Resizer.php

示例12: focus

 /**
  * {@inheritdoc}
  */
 public function focus(ImageInterface $image, $x, $y, $width, $height)
 {
     $imageSize = $image->getSize();
     $currentRatio = $imageSize->getWidth() / $imageSize->getHeight();
     $targetRatio = $currentRatio;
     if ($width !== null && $height !== null) {
         $targetRatio = $width / $height;
     }
     if ($targetRatio < $currentRatio) {
         $height = $imageSize->getHeight();
         $width = $targetRatio * $height;
         $cropY = 0;
         switch ($x) {
             case static::FOCUS_LEFT:
                 $cropX = 0;
                 break;
             case static::FOCUS_RIGHT:
                 $cropX = $imageSize->getWidth() - $width;
                 break;
             default:
                 $cropX = ($imageSize->getWidth() - $width) / 2;
         }
     } else {
         $width = $imageSize->getWidth();
         $height = $width / $targetRatio;
         $cropX = 0;
         switch ($y) {
             case static::FOCUS_TOP:
                 $cropY = 0;
                 break;
             case static::FOCUS_BOTTOM:
                 $cropY = $imageSize->getHeight() - $height;
                 break;
             default:
                 $cropY = ($imageSize->getHeight() - $height) / 2;
         }
     }
     return $image->crop(new Point($cropX, $cropY), new Box($width, $height));
 }
开发者ID:sulu,项目名称:sulu,代码行数:42,代码来源:Focus.php

示例13: save

 /**
  * Save image
  * @return ImageInterface
  */
 public function save()
 {
     if (file_exists($this->_pathObjectFile)) {
         $this->_url = $this->_urlObjectFile;
         return true;
     } elseif (file_exists($this->_pathObjectFileOrigin)) {
         $this->_image = Image::getImagine()->open($this->_pathObjectFileOrigin);
     } elseif (file_exists($this->_pathObjectPlaceholder)) {
         $this->_url = $this->_urlObjectPlaceholder;
         return true;
     } elseif (file_exists($this->_pathObjectPlaceholderOrigin)) {
         $this->_image = Image::getImagine()->open($this->_pathObjectPlaceholderOrigin);
         $this->_pathObjectFile = $this->_pathObjectPlaceholder;
         $this->_urlObjectFile = $this->_urlObjectPlaceholder;
     } elseif (file_exists($this->_pathRootPlaceholder)) {
         $this->_url = $this->_urlRootPlaceholder;
         return true;
     } elseif (file_exists($this->_pathRootPlaceholderOrigin)) {
         $this->_image = Image::getImagine()->open($this->_pathRootPlaceholderOrigin);
         $this->_pathObjectFile = $this->_pathRootPlaceholder;
         $this->_urlObjectFile = $this->_urlRootPlaceholder;
     }
     if ($this->_image) {
         if (!$this->width || !$this->height) {
             $ratio = $this->_image->getSize()->getWidth() / $this->_image->getSize()->getHeight();
             if ($this->width) {
                 $this->height = ceil($this->width / $ratio);
             } else {
                 $this->width = ceil($this->height * $ratio);
             }
             $box = new Box($this->width, $this->height);
             $this->_image->resize($box);
             $this->_image->crop(new Point(0, 0), $box);
         } else {
             $box = new Box($this->width, $this->height);
             $size = $this->_image->getSize();
             if ($size->getWidth() <= $box->getWidth() && $size->getHeight() <= $box->getHeight() || !$box->getWidth() && !$box->getHeight()) {
             } else {
                 $this->_image = $this->_image->thumbnail($box, ManipulatorInterface::THUMBNAIL_OUTBOUND);
                 // calculate points
                 $size = $this->_image->getSize();
                 $startX = 0;
                 $startY = 0;
                 if ($size->getWidth() < $this->width) {
                     $startX = ceil($this->width - $size->getWidth()) / 2;
                 }
                 if ($size->getHeight() < $this->height) {
                     $startY = ceil($this->height - $size->getHeight()) / 2;
                 }
                 // create empty image to preserve aspect ratio of thumbnail
                 $thumb = Image::getImagine()->create($box, new Color('FFF', 100));
                 $thumb->paste($this->_image, new Point($startX, $startY));
                 $this->_image = $thumb;
             }
         }
         $this->_image->save($this->_pathObjectFile);
         $this->_url = $this->_urlObjectFile;
         return true;
     }
     return false;
 }
开发者ID:beowulfenator,项目名称:yii2-dynamic-image,代码行数:65,代码来源:ImageIndexForm.php

示例14: applyToImage

 /**
  * Applies this adjustment to the given Imagine Image object
  *
  * @param ImagineImageInterface $image
  * @return ImagineImageInterface
  * @internal Should never be used outside of the media package. Rely on the ImageService to apply your adjustments.
  */
 public function applyToImage(ImagineImageInterface $image)
 {
     $point = new Point($this->x, $this->y);
     $box = new Box($this->width, $this->height);
     return $image->crop($point, $box);
 }
开发者ID:hlubek,项目名称:neos-development-collection,代码行数:13,代码来源:CropImageAdjustment.php

示例15: apply

 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->crop($this->start, $this->size);
 }
开发者ID:noorafree,项目名称:makmakan,代码行数:7,代码来源:Crop.php


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