本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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));
}
示例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;
}
示例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);
}
示例15: apply
/**
* {@inheritdoc}
*/
public function apply(ImageInterface $image)
{
return $image->crop($this->start, $this->size);
}