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


PHP BoxInterface::contains方法代码示例

本文整理汇总了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;
 }
开发者ID:Danack,项目名称:Imagine,代码行数:42,代码来源:AbstractImage.php

示例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;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:31,代码来源:Image.php

示例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));
 }
开发者ID:BeerMan88,项目名称:yii,代码行数:14,代码来源:BoxTest.php

示例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;
 }
开发者ID:netlogix,项目名称:media,代码行数:21,代码来源:ResizeImageAdjustment.php


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