本文整理汇总了PHP中Imagine\Image\BoxInterface::contains方法的典型用法代码示例。如果您正苦于以下问题:PHP BoxInterface::contains方法的具体用法?PHP BoxInterface::contains怎么用?PHP BoxInterface::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Imagine\Image\BoxInterface
的用法示例。
在下文中一共展示了BoxInterface::contains方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: thumbnail
/**
* {@inheritdoc}
*/
public function thumbnail(BoxInterface $size, $mode = ImageInterface::THUMBNAIL_INSET, $filter = ImageInterface::FILTER_UNDEFINED)
{
if ($mode !== ImageInterface::THUMBNAIL_INSET && $mode !== ImageInterface::THUMBNAIL_OUTBOUND) {
throw new InvalidArgumentException('Invalid mode specified');
}
$imageSize = $this->getSize();
$ratios = array($size->getWidth() / $imageSize->getWidth(), $size->getHeight() / $imageSize->getHeight());
$thumbnail = $this->copy();
$thumbnail->usePalette($this->palette());
$thumbnail->strip();
// if target width is larger than image width
// AND target height is longer than image height
if ($size->contains($imageSize)) {
return $thumbnail;
}
if ($mode === ImageInterface::THUMBNAIL_INSET) {
$ratio = min($ratios);
} else {
$ratio = max($ratios);
}
if ($mode === ImageInterface::THUMBNAIL_OUTBOUND) {
if (!$imageSize->contains($size)) {
$size = new Box(min($imageSize->getWidth(), $size->getWidth()), min($imageSize->getHeight(), $size->getHeight()));
} else {
$imageSize = $thumbnail->getSize()->scale($ratio);
$thumbnail->resize($imageSize, $filter);
}
$thumbnail->crop(new Point(max(0, round(($imageSize->getWidth() - $size->getWidth()) / 2)), max(0, round(($imageSize->getHeight() - $size->getHeight()) / 2))), $size);
} else {
if (!$imageSize->contains($size)) {
$imageSize = $imageSize->scale($ratio);
$thumbnail->resize($imageSize, $filter);
} else {
$imageSize = $thumbnail->getSize()->scale($ratio);
$thumbnail->resize($imageSize, $filter);
}
}
return $thumbnail;
}
示例2: thumbnail
/**
* {@inheritdoc}
*/
public function thumbnail(BoxInterface $size, $mode = ImageInterface::THUMBNAIL_INSET)
{
if ($mode !== ImageInterface::THUMBNAIL_INSET && $mode !== ImageInterface::THUMBNAIL_OUTBOUND) {
throw new InvalidArgumentException('Invalid mode specified');
}
$imageSize = $this->getSize();
$thumbnail = $this->copy();
// if target width is larger than image width
// AND target height is longer than image height
if ($size->contains($imageSize)) {
return $thumbnail;
}
// if target width is larger than image width
// OR target height is longer than image height
if (!$imageSize->contains($size)) {
$size = new Box(min($imageSize->getWidth(), $size->getWidth()), min($imageSize->getHeight(), $size->getHeight()));
}
try {
if ($mode === ImageInterface::THUMBNAIL_INSET) {
$thumbnail->gmagick->thumbnailimage($size->getWidth(), $size->getHeight(), true);
} elseif ($mode === ImageInterface::THUMBNAIL_OUTBOUND) {
$thumbnail->gmagick->cropthumbnailimage($size->getWidth(), $size->getHeight());
}
} catch (\GmagickException $e) {
throw new RuntimeException('Thumbnail operation failed', $e->getCode(), $e);
}
return $thumbnail;
}
示例3: testShouldDetermineIfASizeContainsABoxAtAStartPosition
/**
* @covers Imagine\Image\Box::contains
*
* @dataProvider getSizeBoxStartAndExpected
*
* @param BoxInterface $size
* @param BoxInterface $box
* @param PointInterface $start
* @param Boolean $expected
*/
public function testShouldDetermineIfASizeContainsABoxAtAStartPosition(BoxInterface $size, BoxInterface $box, PointInterface $start, $expected)
{
$this->assertEquals($expected, $size->contains($box, $start));
}
示例4: calculateOutboundBox
/**
* Calculate the final dimensions for an outbound box. usually exactly the requested width and height unless that
* would require upscaling and it is not allowed.
*
* @param BoxInterface $originalDimensions
* @param integer $requestedWidth
* @param integer $requestedHeight
* @return BoxInterface
*/
protected function calculateOutboundBox(BoxInterface $originalDimensions, $requestedWidth, $requestedHeight)
{
$newDimensions = new Box($requestedWidth, $requestedHeight);
if ($this->getAllowUpScaling() === TRUE || $originalDimensions->contains($newDimensions) === TRUE) {
return $newDimensions;
}
// We need to make sure that the new dimensions are such that no upscaling is needed.
$ratios = array($originalDimensions->getWidth() / $requestedWidth, $originalDimensions->getHeight() / $requestedHeight);
$ratio = min($ratios);
$newDimensions = $newDimensions->scale($ratio);
return $newDimensions;
}