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


PHP ImageInterface::resize方法代码示例

本文整理汇总了PHP中Imagine\Image\ImageInterface::resize方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageInterface::resize方法的具体用法?PHP ImageInterface::resize怎么用?PHP ImageInterface::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Imagine\Image\ImageInterface的用法示例。


在下文中一共展示了ImageInterface::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: resize

 /**
  * Re-sizes the image. If $height is not specified, it will default to $width, creating a square.
  *
  * @param int      $targetWidth
  * @param int|null $targetHeight
  *
  * @return Image
  */
 public function resize($targetWidth, $targetHeight = null)
 {
     $this->normalizeDimensions($targetWidth, $targetHeight);
     if ($this->_isAnimatedGif) {
         $this->_image->layers()->coalesce();
         // Create a new image instance to avoid object references messing up our dimensions.
         $newSize = new \Imagine\Image\Box($targetWidth, $targetHeight);
         $gif = $this->_instance->create($newSize);
         $gif->layers()->remove(0);
         foreach ($this->_image->layers() as $layer) {
             $resizedLayer = $layer->resize($newSize, $this->_getResizeFilter());
             $gif->layers()->add($resizedLayer);
             // Let's update dateUpdated in case this is going to take awhile.
             if ($index = craft()->assetTransforms->getActiveTransformIndexModel()) {
                 craft()->assetTransforms->storeTransformIndexData($index);
             }
         }
         $this->_image = $gif;
     } else {
         if (craft()->images->isImagick()) {
             $this->_image->smartResize(new \Imagine\Image\Box($targetWidth, $targetHeight), (bool) craft()->config->get('preserveImageColorProfiles'), $this->_quality);
         } else {
             $this->_image->resize(new \Imagine\Image\Box($targetWidth, $targetHeight), $this->_getResizeFilter());
         }
     }
     return $this;
 }
开发者ID:vescoyez,项目名称:portfolio_v2,代码行数:35,代码来源:Image.php

示例2: resize

	/**
	 * Re-sizes the image. If $height is not specified, it will default to $width, creating a square.
	 *
	 * @param int      $targetWidth
	 * @param int|null $targetHeight
	 *
	 * @return Image
	 */
	public function resize($targetWidth, $targetHeight = null)
	{
		$this->_normalizeDimensions($targetWidth, $targetHeight);

		if ($this->_isAnimatedGif)
		{

			// Create a new image instance to avoid object references messing up our dimensions.
			$newSize = new \Imagine\Image\Box($targetWidth, $targetHeight);
			$gif = $this->_instance->create($newSize);
			$gif->layers()->remove(0);

			foreach ($this->_image->layers() as $layer)
			{
				$resizedLayer = $layer->resize($newSize, $this->_getResizeFilter());
				$gif->layers()->add($resizedLayer);
			}

			$this->_image = $gif;
		}
		else
		{
			$this->_image->resize(new \Imagine\Image\Box($targetWidth, $targetHeight), $this->_getResizeFilter());
		}

		return $this;
	}
开发者ID:harish94,项目名称:Craft-Release,代码行数:35,代码来源:Image.php

示例3: imageResize

 /**
  * @return null|string
  */
 public function imageResize()
 {
     $this->openImage();
     $width = $this->imageWidth;
     $height = $this->imageHeight;
     $maxWidth = $this->imageMaxWidth;
     $maxHeight = $this->imageMaxHeight;
     if ($maxWidth === null && $maxHeight !== null) {
         $imageBox = $this->image->getSize()->heighten($maxHeight);
     } elseif ($maxHeight === null && $maxWidth !== null) {
         $imageBox = $this->image->getSize()->widen($maxWidth);
     } elseif ($maxHeight !== null && $maxWidth !== null) {
         $imageBox = $this->image->getSize()->heighten($maxHeight)->widen($maxWidth);
     } elseif ($width !== null && $height !== null) {
         $imageBox = new \Imagine\Image\Box($width, $height);
     } elseif ($width === null && $height !== null) {
         $imageBox = new \Imagine\Image\Box($this->image->getSize()->getWidth(), $height);
     } elseif ($width !== null && $height === null) {
         $imageBox = new \Imagine\Image\Box($width, $this->image->getSize()->getHeight());
     } else {
         $imageBox = new \Imagine\Image\Box($this->image->getSize()->getWidth(), $this->image->getSize()->getHeight());
     }
     $this->image = $this->image->resize($imageBox);
     return $this;
 }
开发者ID:fraym,项目名称:core,代码行数:28,代码来源:Editor.php

示例4: apply

 public function apply(ImageInterface &$image, ImagineInterface $imagine)
 {
     $box = $image->getSize();
     $width = Helper::percentValue($this->_width, $box->getWidth());
     $height = Helper::percentValue($this->_height, $box->getHeight());
     // no upscale
     if ($box->getWidth() <= $width && $box->getHeight() <= $height) {
         return;
     }
     Helper::scaleSize($width, $height, $box);
     $image->resize(new Box($width, $height));
 }
开发者ID:x000000,项目名称:storage-manager,代码行数:12,代码来源:Resize.php

示例5: performResize

 /**
  * Performs resize of the image. Imagine component is used.
  *
  * @param ImageInterface $imagine
  * @param                $resize
  * @param bool           $crop
  *
  * @return BoxInterface
  */
 private function performResize($imagine, $resize, $crop = true)
 {
     $box = $imagine->getSize();
     list($width, $height) = Utils::getDimension($resize);
     $box = $box->scale(max($width / $box->getWidth(), $height / $box->getHeight()));
     $imagine->resize($box);
     if ($crop) {
         $point = new Point(($box->getWidth() - $width) / 2, ($box->getHeight() - $height) / 2);
         $imagine->crop($point, new Box($width, $height));
     }
     return $box;
 }
开发者ID:voodoo-mobile,项目名称:yii2-image,代码行数:21,代码来源:UploadedImage.php

示例6: imageResize

 /**
  * Command image resize
  * 
  * @param int $width
  * @param int $height
  * 
  * @return void
  */
 protected function imageResize($width, $height)
 {
     $width = (int) $width;
     $height = (int) $height;
     if ($width <= 0) {
         throw new BadMethodCallException('Invalid parameter width for command "resize"');
     }
     if ($height <= 0) {
         throw new BadMethodCallException('Invalid parameter height for command "resize"');
     }
     $this->image->resize(new Box($width, $height));
 }
开发者ID:dgram,项目名称:zf2-imageresizer,代码行数:20,代码来源:ImageProcessing.php

示例7: execute

 /**
  * {@inheritdoc}
  */
 public function execute(ImageInterface &$image, $parameters)
 {
     $size = $image->getSize();
     $retina = isset($parameters['retina']) && $parameters['retina'] != 'false' ? 2 : 1;
     $newWidth = isset($parameters['x']) ? intval($parameters['x']) * $retina : null;
     $newHeight = isset($parameters['y']) ? intval($parameters['y']) * $retina : null;
     if ($newHeight == null) {
         $newHeight = $size->getHeight() / $size->getWidth() * $newWidth;
     }
     if ($newWidth == null) {
         $newWidth = $size->getWidth() / $size->getHeight() * $newHeight;
     }
     $image->resize(new Box($newWidth, $newHeight));
 }
开发者ID:ollietb,项目名称:sulu,代码行数:17,代码来源:ResizeCommand.php

示例8: resize

 /**
  * Re-sizes the image. If $height is not specified, it will default to $width, creating a square.
  *
  * @param int      $targetWidth
  * @param int|null $targetHeight
  *
  * @return Image
  */
 public function resize($targetWidth, $targetHeight = null)
 {
     $this->normalizeDimensions($targetWidth, $targetHeight);
     if ($this->_isAnimatedGif) {
         // Create a new image instance to avoid object references messing up our dimensions.
         $newSize = new \Imagine\Image\Box($targetWidth, $targetHeight);
         $gif = $this->_instance->create($newSize);
         $gif->layers()->remove(0);
         foreach ($this->_image->layers() as $layer) {
             $resizedLayer = $layer->resize($newSize, $this->_getResizeFilter());
             $gif->layers()->add($resizedLayer);
         }
         $this->_image = $gif;
     } else {
         if (craft()->images->isImagick()) {
             $this->_image->smartResize(new \Imagine\Image\Box($targetWidth, $targetHeight), (bool) craft()->config->get('preserveImageColorProfiles'), $this->_quality);
         } else {
             $this->_image->resize(new \Imagine\Image\Box($targetWidth, $targetHeight), $this->_getResizeFilter());
         }
     }
     return $this;
 }
开发者ID:paulcarvill,项目名称:Convergence-craft,代码行数:30,代码来源:Image.php

示例9: applyResize

 /**
  * Process image resizing, with borders or cropping. If $dest_width and $dest_height
  * are both null, no resize is performed.
  *
  * @param  ImagineInterface $imagine     the Imagine instance
  * @param  ImageInterface   $image       the image to process
  * @param  int              $dest_width  the required width
  * @param  int              $dest_height the required height
  * @param  int              $resize_mode the resize mode (crop / bands / keep image ratio)p
  * @param  string           $bg_color    the bg_color used for bands
  * @param  bool             $allow_zoom  if true, image may be zoomed to matchrequired size. If false, image is not zoomed.
  * @return ImageInterface   the resized image.
  */
 protected function applyResize(ImagineInterface $imagine, ImageInterface $image, $dest_width, $dest_height, $resize_mode, $bg_color, $allow_zoom = false)
 {
     if (!(is_null($dest_width) && is_null($dest_height))) {
         $width_orig = $image->getSize()->getWidth();
         $height_orig = $image->getSize()->getHeight();
         $ratio = $width_orig / $height_orig;
         if (is_null($dest_width)) {
             $dest_width = $dest_height * $ratio;
         }
         if (is_null($dest_height)) {
             $dest_height = $dest_width / $ratio;
         }
         if (is_null($resize_mode)) {
             $resize_mode = self::KEEP_IMAGE_RATIO;
         }
         $width_diff = $dest_width / $width_orig;
         $height_diff = $dest_height / $height_orig;
         $delta_x = $delta_y = $border_width = $border_height = 0;
         if ($width_diff > 1 && $height_diff > 1) {
             $resize_width = $width_orig;
             $resize_height = $height_orig;
             // When cropping, be sure to always generate an image which is
             //  no smaller than the required size, zooming it if required.
             if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
                 if ($allow_zoom) {
                     if ($width_diff > $height_diff) {
                         $resize_width = $dest_width;
                         $resize_height = intval($height_orig * $dest_width / $width_orig);
                         $delta_y = ($resize_height - $dest_height) / 2;
                     } else {
                         $resize_height = $dest_height;
                         $resize_width = intval($width_orig * $resize_height / $height_orig);
                         $delta_x = ($resize_width - $dest_width) / 2;
                     }
                 } else {
                     // No zoom : final image may be smaller than the required size.
                     $dest_width = $resize_width;
                     $dest_height = $resize_height;
                 }
             }
         } elseif ($width_diff > $height_diff) {
             // Image height > image width
             $resize_height = $dest_height;
             $resize_width = intval($width_orig * $resize_height / $height_orig);
             if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
                 $resize_width = $dest_width;
                 $resize_height = intval($height_orig * $dest_width / $width_orig);
                 $delta_y = ($resize_height - $dest_height) / 2;
             } elseif ($resize_mode != self::EXACT_RATIO_WITH_BORDERS) {
                 $dest_width = $resize_width;
             }
         } else {
             // Image width > image height
             $resize_width = $dest_width;
             $resize_height = intval($height_orig * $dest_width / $width_orig);
             if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
                 $resize_height = $dest_height;
                 $resize_width = intval($width_orig * $resize_height / $height_orig);
                 $delta_x = ($resize_width - $dest_width) / 2;
             } elseif ($resize_mode != self::EXACT_RATIO_WITH_BORDERS) {
                 $dest_height = $resize_height;
             }
         }
         $image->resize(new Box($resize_width, $resize_height));
         if ($resize_mode == self::EXACT_RATIO_WITH_BORDERS) {
             $border_width = intval(($dest_width - $resize_width) / 2);
             $border_height = intval(($dest_height - $resize_height) / 2);
             $canvas = new Box($dest_width, $dest_height);
             return $imagine->create($canvas, $bg_color)->paste($image, new Point($border_width, $border_height));
         } elseif ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
             $image->crop(new Point($delta_x, $delta_y), new Box($dest_width, $dest_height));
         }
     }
     return $image;
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:88,代码来源:Image.php

示例10: resizeImageByHeight

 /**
  * @param ImageInterface $image
  * @param $requestHeight
  */
 protected function resizeImageByHeight($image, $requestHeight)
 {
     $imageSizeBox = $image->getSize();
     $resizeBox = $imageSizeBox->heighten($requestHeight);
     $image->resize($resizeBox);
 }
开发者ID:xjflyttp,项目名称:yii2-thumb-action,代码行数:10,代码来源:ThumbAction.php

示例11: applyResize

 /**
  * Process image resizing, with borders or cropping. If $dest_width and $dest_height
  * are both null, no resize is performed.
  *
  * @param  ImagineInterface $imagine     the Imagine instance
  * @param  ImageInterface   $image       the image to process
  * @param  int              $dest_width  the required width
  * @param  int              $dest_height the required height
  * @param  int              $resize_mode the resize mode (crop / bands / keep image ratio)p
  * @param  string           $bg_color    the bg_color used for bands
  * @return ImageInterface   the resized image.
  */
 protected function applyResize(ImagineInterface $imagine, ImageInterface $image, $dest_width, $dest_height, $resize_mode, $bg_color)
 {
     if (!(is_null($dest_width) && is_null($dest_height))) {
         $width_orig = $image->getSize()->getWidth();
         $height_orig = $image->getSize()->getHeight();
         if (is_null($dest_width)) {
             $dest_width = $width_orig;
         }
         if (is_null($dest_height)) {
             $dest_height = $height_orig;
         }
         if (is_null($resize_mode)) {
             $resize_mode = self::KEEP_IMAGE_RATIO;
         }
         $width_diff = $dest_width / $width_orig;
         $height_diff = $dest_height / $height_orig;
         $delta_x = $delta_y = $border_width = $border_height = 0;
         if ($width_diff > 1 && $height_diff > 1) {
             $next_width = $width_orig;
             $next_height = $height_orig;
             $dest_width = $resize_mode == self::EXACT_RATIO_WITH_BORDERS ? $dest_width : $next_width;
             $dest_height = $resize_mode == self::EXACT_RATIO_WITH_BORDERS ? $dest_height : $next_height;
         } elseif ($width_diff > $height_diff) {
             // Image height > image width
             $next_height = $dest_height;
             $next_width = intval($width_orig * $next_height / $height_orig);
             if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
                 $next_width = $dest_width;
                 $next_height = intval($height_orig * $dest_width / $width_orig);
                 $delta_y = ($next_height - $dest_height) / 2;
             } elseif ($resize_mode != self::EXACT_RATIO_WITH_BORDERS) {
                 $dest_width = $next_width;
             }
         } else {
             // Image width > image height
             $next_width = $dest_width;
             $next_height = intval($height_orig * $dest_width / $width_orig);
             if ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
                 $next_height = $dest_height;
                 $next_width = intval($width_orig * $next_height / $height_orig);
                 $delta_x = ($next_width - $dest_width) / 2;
             } elseif ($resize_mode != self::EXACT_RATIO_WITH_BORDERS) {
                 $dest_height = $next_height;
             }
         }
         $image->resize(new Box($next_width, $next_height));
         if ($resize_mode == self::EXACT_RATIO_WITH_BORDERS) {
             $border_width = intval(($dest_width - $next_width) / 2);
             $border_height = intval(($dest_height - $next_height) / 2);
             $canvas = new Box($dest_width, $dest_height);
             return $imagine->create($canvas, $bg_color)->paste($image, new Point($border_width, $border_height));
         } elseif ($resize_mode == self::EXACT_RATIO_WITH_CROP) {
             $image->crop(new Point($delta_x, $delta_y), new Box($dest_width, $dest_height));
         }
     }
     return $image;
 }
开发者ID:alex63530,项目名称:thelia,代码行数:69,代码来源:Image.php

示例12: resizeExact

 /**
  * Resize an image to an exact width and height.
  *
  * @param  ImageInterface $image
  * @param  string $width - The image's new width.
  * @param  string $height - The image's new height.
  * @return ImageInterface
  */
 protected function resizeExact(ImageInterface $image, $width, $height)
 {
     return $image->resize(new Box($width, $height));
 }
开发者ID:JoelFieldCodeProjects,项目名称:test,代码行数:12,代码来源:Resizer.php

示例13: expandImage

 /**
  * Расширяет маленькую картинку по заданной стратегии
  *
  * @param \Imagine\Image\ImageInterface $image
  * @param int $widthFormat
  * @param int $heightFormat
  * @param int $mode
  *
  * @return \Imagine\Image\ImageInterface
  */
 protected static function expandImage($image, $widthFormat, $heightFormat, $mode)
 {
     $size = $image->getSize();
     $width = $size->getWidth();
     $height = $size->getHeight();
     if ($width < $widthFormat || $height < $heightFormat) {
         // расширяю картинку
         if ($mode == self::MODE_THUMBNAIL_CUT) {
             if ($width < $widthFormat && $height >= $heightFormat) {
                 $size = $size->widen($widthFormat);
             } else {
                 if ($width >= $widthFormat && $height < $heightFormat) {
                     $size = $size->heighten($heightFormat);
                 } else {
                     if ($width < $widthFormat && $height < $heightFormat) {
                         // определяю как расширять по ширине или по высоте
                         if ($width / $widthFormat < $height / $heightFormat) {
                             $size = $size->widen($widthFormat);
                         } else {
                             $size = $size->heighten($heightFormat);
                         }
                     }
                 }
             }
             $image->resize($size);
         } else {
             if ($width < $widthFormat && $height >= $heightFormat) {
                 $size = $size->heighten($heightFormat);
             } else {
                 if ($width >= $widthFormat && $height < $heightFormat) {
                     $size = $size->widen($widthFormat);
                 } else {
                     if ($width < $widthFormat && $height < $heightFormat) {
                         // определяю как расширять по ширине или по высоте
                         if ($width / $widthFormat < $height / $heightFormat) {
                             $size = $size->heighten($heightFormat);
                         } else {
                             $size = $size->widen($widthFormat);
                         }
                     }
                 }
             }
             $image->resize($size);
         }
     }
     return $image;
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:57,代码来源:FileUpload.php

示例14: 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

示例15: apply

 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->resize($this->size);
 }
开发者ID:anillaogi016,项目名称:zend-admin,代码行数:7,代码来源:Resize.php


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