當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ImageInterface::thumbnail方法代碼示例

本文整理匯總了PHP中Imagine\Image\ImageInterface::thumbnail方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageInterface::thumbnail方法的具體用法?PHP ImageInterface::thumbnail怎麽用?PHP ImageInterface::thumbnail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Imagine\Image\ImageInterface的用法示例。


在下文中一共展示了ImageInterface::thumbnail方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generateThumb

 /**
  * @param ImageInterface $image
  * @return ImageInterface
  */
 public function generateThumb(ImageInterface $image, $width, $height)
 {
     $background = isset($this->options["background"]) ? $this->options["background"] : null;
     $fitSize = isset($this->options["fitSize"]) ? $this->options["fitSize"] : true;
     $sizeBox = new Box($width, $height);
     $thumbMode = ImageInterface::THUMBNAIL_INSET;
     $thumb = $image->thumbnail($sizeBox, $thumbMode);
     // fill the area
     if ($fitSize) {
         $palette = new RGB();
         if (!$background || $background == "transparent") {
             $backgroundColor = $palette->color("fff", 1);
         } else {
             $backgroundColor = $palette->color($background);
         }
         // source http://harikt.com/blog/2012/12/17/resize-image-keeping-aspect-ratio-in-imagine/
         $realThumb = Image::create($sizeBox, $backgroundColor);
         $sizeR = $thumb->getSize();
         $widthR = $sizeR->getWidth();
         $heightR = $sizeR->getHeight();
         $startX = $startY = 0;
         if ($widthR < $width) {
             $startX = ($width - $widthR) / 2;
         }
         if ($heightR < $height) {
             $startY = ($height - $heightR) / 2;
         }
         $realThumb->paste($thumb, new Point($startX, $startY));
     } else {
         $realThumb = $thumb;
     }
     return $realThumb;
 }
開發者ID:gsouf,項目名稱:thumbz,代碼行數:37,代碼來源:ThumbMaker.php

示例2: apply

 public function apply(\Imagine\Image\ImageInterface $original)
 {
     $originalThumb = $original->thumbnail($this->size, 'inset');
     $image = $this->createCanvas();
     $image = $this->pasteCentered($image, $originalThumb);
     return $image;
 }
開發者ID:rtablada,項目名稱:resize-and-pad,代碼行數:7,代碼來源:ResizeAndPad.php

示例3: processArguments

 /**
  * @param list ($width, $height, $method) $arguments;
  */
 public function processArguments(ImagineImage $imagineImage, array $arguments, array $options = array())
 {
     list($width, $height, $method) = $arguments;
     if ($method == 'standard') {
         $style = ImagineImage::THUMBNAIL_INSET;
     } else {
         $style = ImagineImage::THUMBNAIL_OUTBOUND;
     }
     return $imagineImage->thumbnail(new Box($width, $height), $style);
 }
開發者ID:pscheit,項目名稱:psc-cms-image,代碼行數:13,代碼來源:ThumbnailTransformation.php

示例4: imageThumb

 /**
  * Command image thumb
  * 
  * @param int $width
  * @param int $height
  * 
  * @return void
  */
 protected function imageThumb($width, $height)
 {
     $width = (int) $width;
     $height = (int) $height;
     if ($width <= 0) {
         throw new BadMethodCallException('Invalid parameter width for command "thumb"');
     }
     if ($height <= 0) {
         throw new BadMethodCallException('Invalid parameter height for command "thumb"');
     }
     $this->image = $this->image->thumbnail(new Box($width, $height));
 }
開發者ID:dgram,項目名稱:zf2-imageresizer,代碼行數:20,代碼來源:ImageProcessing.php

示例5: fit

 /**
  * Fit image to area
  * @param integer $width the width in pixels to create the thumbnail
  * @param integer $height the height in pixels to create the thumbnail
  * @param string $mode
  * @return static
  */
 public function fit($width, $height, $mode = ManipulatorInterface::THUMBNAIL_INSET)
 {
     $box = new Box($width, $height);
     $this->image = $this->image->thumbnail($box, $mode);
     // create empty image to preserve aspect ratio of thumbnail
     $thumb = static::getImagine()->create($box, new Color('FFF', 100));
     // calculate points
     $size = $this->image->getSize();
     $startX = 0;
     $startY = 0;
     if ($size->getWidth() < $width) {
         $startX = ceil($width - $size->getWidth()) / 2;
     }
     if ($size->getHeight() < $height) {
         $startY = ceil($height - $size->getHeight()) / 2;
     }
     $thumb->paste($this->image, new Point($startX, $startY));
     $this->image = $thumb;
     return $this;
 }
開發者ID:maddoger,項目名稱:yii2-imagecache,代碼行數:27,代碼來源:Image.php

示例6: thumbnailCropScale

 /**
  * Create a thumbnail by scaling an image and cropping it to fit the exact dimensions
  *
  * @param ImageInterface $image The ImageInterface instance from Imagine
  * @param int $targetWidth The width in pixels
  * @param int $targetHeight The height in pixels
  * @return ImageInterface
  */
 protected function thumbnailCropScale(ImageInterface $image, $targetWidth, $targetHeight)
 {
     $target = new Box($targetWidth, $targetHeight);
     $sourceSize = $image->getSize();
     if ($sourceSize->getWidth() > $sourceSize->getHeight()) {
         $width = $sourceSize->getWidth() * ($target->getHeight() / $sourceSize->getHeight());
         $height = $targetHeight;
         $cropPoint = new Point((int) (max($width - $target->getWidth(), 0) / 2), 0);
     } else {
         $height = $sourceSize->getHeight() * ($target->getWidth() / $sourceSize->getWidth());
         $width = $targetWidth;
         $cropPoint = new Point(0, (int) (max($height - $target->getHeight(), 0) / 2));
     }
     $box = new Box($width, $height);
     return $image->thumbnail($box, ImageInterface::THUMBNAIL_OUTBOUND)->crop($cropPoint, $target);
 }
開發者ID:edukondaluetg,項目名稱:CakePHP3-Proffer,代碼行數:24,代碼來源:ImageTransform.php

示例7: 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;
 }
開發者ID:beowulfenator,項目名稱:yii2-dynamic-image,代碼行數:65,代碼來源:ImageIndexForm.php

示例8: apply

 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->thumbnail($this->size, $this->mode);
 }
開發者ID:anillaogi016,項目名稱:zend-admin,代碼行數:7,代碼來源:Thumbnail.php

示例9: handleImageManipulation

 /**
  * Handle image manipulation.
  *
  * @param  \Imagine\Image\ImageInterface  $image
  * @param  array  $data
  *
  * @return \Imagine\Image\ImageInterface
  */
 protected function handleImageManipulation(ImageInterface $image, array $data)
 {
     $width = $height = $data['dimension'];
     return $image->thumbnail(new Box($width, $height), $data['mode'], $data['filter']);
 }
開發者ID:bibimoto,項目名稱:imagine,代碼行數:13,代碼來源:CreateThumbnail.php

示例10: applyThumbnailFilter

 /**
  * @param \Imagine\Image\ImageInterface $image
  * @param array $options
  * @return \Imagine\Image\ImageInterface
  */
 protected function applyThumbnailFilter(ImageInterface $image, $options)
 {
     // Defaults
     $size = new Box(120, 120);
     $mode = ImageInterface::THUMBNAIL_OUTBOUND;
     if (isset($options['size']) && count($options['size']) == 2) {
         list($width, $height) = $options['size'];
         $size = new Box($width, $height);
     }
     if (isset($options['mode']) && $options['mode'] == 'inset') {
         $mode = ImageInterface::THUMBNAIL_INSET;
     }
     return $image->thumbnail($size, $mode);
 }
開發者ID:getherbie,項目名稱:plugin-imagine,代碼行數:19,代碼來源:ImagineExtension.php

示例11: thumbnailCommand

 /**
  * @param \Imagine\Image\ImageInterface $image
  * @param array $commandOptions array('size' => ('width' => 123, 'height => 456), 'mode' => 'outbound')
  * @return \Imagine\Image\ImageInterface
  */
 protected function thumbnailCommand(\Imagine\Image\ImageInterface $image, array $commandOptions)
 {
     if (!isset($commandOptions['size'])) {
     }
     $dimensions = $this->parseBox($commandOptions['size']);
     if (isset($commandOptions['mode']) && $commandOptions['mode'] === 'outbound') {
         $mode = \Imagine\Image\ManipulatorInterface::THUMBNAIL_OUTBOUND;
     } else {
         $mode = \Imagine\Image\ManipulatorInterface::THUMBNAIL_INSET;
     }
     return $image->thumbnail($dimensions, $mode);
 }
開發者ID:sdrech,項目名稱:example_quiz,代碼行數:17,代碼來源:ImageService.php

示例12: scale

 /**
  * {@inheritdoc}
  */
 public function scale(ImageInterface $image, $x, $y, $mode = ImageInterface::THUMBNAIL_OUTBOUND, $forceRatio = true, $retina = false)
 {
     list($newWidth, $newHeight) = $this->getHeightWidth($x, $y, $retina, $forceRatio, $image->getSize(), $mode);
     return $image->thumbnail(new Box($newWidth, $newHeight), $mode);
 }
開發者ID:sulu,項目名稱:sulu,代碼行數:8,代碼來源:Scaler.php


注:本文中的Imagine\Image\ImageInterface::thumbnail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。