本文整理匯總了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;
}