当前位置: 首页>>代码示例>>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;未经允许,请勿转载。