當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。