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


PHP Image::resize方法代码示例

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


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

示例1: resize

 /**
  * Define Resize
  *
  * @param int     $width
  * @param int     $height
  * @param boolean $force
  *
  * @return Imagine
  */
 public function resize($width, $height, $force = false)
 {
     $width = intval($width);
     $height = intval($height);
     $callback = function () {
     };
     if ($width > 0 || $height > 0) {
         // AutoScale - aspectRatio
         if (!$force) {
             $callback = function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             };
         }
         $width = $width ?: null;
         $height = $height ?: null;
         $this->image->resize($width, $height, $callback);
     }
     return $this;
 }
开发者ID:naturalweb,项目名称:nwlaravel,代码行数:29,代码来源:Imagine.php

示例2: process

 public function process()
 {
     $data = $this->loadData();
     if ($data !== true) {
         return $this->failure($data);
     }
     $mobile = (int) $this->getProperty('mobile', 0);
     if ($mobile == 1) {
         $orientation = $this->img->exif('Orientation');
         switch ($orientation) {
             case 3:
                 $this->img->rotate(180);
                 break;
             case 6:
                 $this->img->rotate(-90);
                 break;
             case 8:
                 $this->img->rotate(90);
                 break;
         }
     }
     if (isset($this->data['rotate'])) {
         $rotate = $this->data['rotate'] * -1.0;
         $this->img->rotate($rotate);
     }
     $crop = $this->getProperty('crop', 0);
     if ($crop == 1 && isset($this->data['width']) && isset($this->data['height'])) {
         $width = intval($this->data['width']);
         $height = intval($this->data['height']);
         if ($height != 0 && $width != 0) {
             $this->img->crop($width, $height, intval($this->data['x']), intval($this->data['y']));
         }
     }
     $fileName = $this->generateUniqueFileName();
     $width = (int) $this->md->getOption('resizer.width', null, 0);
     $width = empty($width) ? null : $width;
     $height = (int) $this->md->getOption('resizer.height', null, 0);
     $height = empty($height) ? null : $height;
     $profileName = $this->getProperty('profile', '');
     if (!empty($profileName) && $crop == 1) {
         $profiles = $this->modx->fromJSON($this->md->getOption('cropper.profiles', null, '[]'));
         foreach ($profiles as $profile) {
             if (!isset($profile['name']) || $profile['name'] != $profileName) {
                 continue;
             }
             $profileWidth = (int) $profile['width'];
             $profileHeight = (int) $profile['height'];
             $width = empty($profileWidth) ? $width : $profileWidth;
             $height = empty($profileHeight) ? $height : $profileHeight;
             break;
         }
     }
     if ($width != null || $height != null) {
         $this->img->resize($width, $height, function ($constraint) {
             /** @var \Intervention\Image\Constraint $constraint */
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     }
     $this->img->save($this->uploadPath . $fileName . '.' . $this->extension);
     return $this->success('', array('path' => $this->uploadURL . $fileName . '.' . $this->extension, 'name' => $this->originalName));
 }
开发者ID:ashliewebb,项目名称:ashliewebb,代码行数:62,代码来源:imageupload.class.php

示例3: resizeImage

 public function resizeImage($size)
 {
     $this->image->resize($size, null, function ($constraint) {
         $constraint->aspectRatio();
     });
     return $this;
 }
开发者ID:katzefudder,项目名称:Photoindexer,代码行数:7,代码来源:ImageHandler.php

示例4: getAveragePixelColor

 /**
  * @return string
  */
 public function getAveragePixelColor()
 {
     $this->intervention->resize(1, 1);
     $color = substr($this->intervention->pickColor(0, 0, 'hex'), 1);
     $this->intervention->reset();
     return $color;
 }
开发者ID:tippingcanoe,项目名称:imager,代码行数:10,代码来源:ImageData.php

示例5: resizeImage

 /**
  * Resize the image.
  *
  * @param integer $width
  * @param integer $height
  * @param bool $aspectRatio
  * @return $this
  */
 public function resizeImage($width, $height, $aspectRatio = true)
 {
     $this->image->resize($width, $height, function ($constraint) use($aspectRatio) {
         if ($aspectRatio) {
             $constraint->aspectRatio();
         }
         $constraint->upsize();
     });
     return $this;
 }
开发者ID:BePsvPT,项目名称:CCU,代码行数:18,代码来源:ImageAbstract.php

示例6: applyFilter

 public function applyFilter(Image $image)
 {
     return $image->resize(420, 420, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     });
 }
开发者ID:stjanilofts,项目名称:ofncms,代码行数:7,代码来源:productlistFilter.php

示例7: applyFilter

 public function applyFilter(Image $image)
 {
     return $image->resize(150, 100, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     })->encode('jpg', 75);
 }
开发者ID:stjanilofts,项目名称:normx,代码行数:7,代码来源:logoFilter.php

示例8: run

 /**
  * @param \Intervention\Image\Image $image
  */
 public function run(Image $image)
 {
     $callback = function (Constraint $constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     };
     $image->resize($this->maxWidth, $this->maxHeight, $callback)->interlace($this->interlace);
 }
开发者ID:livetyping,项目名称:hermitage,代码行数:11,代码来源:Optimize.php

示例9: applyFilter

 public function applyFilter(Image $image)
 {
     // resize the image to a height of 1080 and constrain aspect ratio (auto width)
     // prevent possible upsizing
     return $image->resize(1440, null, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     })->blur(12);
 }
开发者ID:jasonraimondi,项目名称:twitterclone,代码行数:9,代码来源:Blur.php

示例10: upload

 /**
  * Upload file to storage.
  *
  * @return void
  */
 public function upload(Image $image)
 {
     $filename = str_pad($this->id, 5, '0', STR_PAD_LEFT) . '.jpg';
     $path = storage_path('app') . "/tmp/";
     $image->resize(320, 200)->encode('jpg', '85')->save($path . $filename);
     $this->storage->move("tmp/" . $filename, config('params.screenshots_path') . "/" . $filename);
     $this->filename = $filename;
     $this->save();
 }
开发者ID:figura4,项目名称:c64,代码行数:14,代码来源:Screenshot.php

示例11: transform

 /**
  * Transform the image
  *
  * @param Image $image
  * @return Image
  */
 public function transform(Image $image)
 {
     if ($this->width and $this->height) {
         $image->grab($this->width, $this->height);
     } elseif ($this->width or $this->height) {
         $image->resize($this->width, $this->height, true, false);
     }
     return $image;
 }
开发者ID:nckg,项目名称:imageme,代码行数:15,代码来源:Resize.php

示例12: apply

 public function apply(Image $image)
 {
     $iHeight = $image->height();
     $iWidth = $image->width();
     if ($iHeight == $height && $iWidth == $width) {
         return $image;
     }
     $iRatio = $iWidth / $iHeight;
     $Ratio = $width / $height;
     if ($iRatio > $Ratio) {
         $image->resize($width, null, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     } else {
         $image->resize(null, $height, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     }
     return $image;
 }
开发者ID:igaster,项目名称:laravel-image-versions,代码行数:22,代码来源:Thumbnail.php

示例13: fit

 protected function fit()
 {
     if ($this->width !== null || $this->height !== null) {
         if ($this->fit === self::FIT_CROP && $this->width && $this->height) {
             $this->image->fit($this->width, $this->height, function ($constraint) {
                 /* @var $constraint \Intervention\Image\Constraint */
                 $constraint->aspectRatio();
             });
             return;
         }
         if ($this->fit === self::FIT_MIN || $this->fit === self::FIT_MAX) {
             if ($this->fit === self::FIT_MAX) {
                 $this->image->resize($this->width, $this->height, function ($constraint) {
                     /* @var $constraint \Intervention\Image\Constraint */
                     $constraint->aspectRatio();
                     $constraint->upsize();
                 });
                 $this->image->resizeCanvas($this->width, $this->height, 'top-left');
             }
             if ($this->fit === self::FIT_MIN) {
                 $height = $this->image->getHeight() < $this->height ? $this->image->getHeight() : $this->height;
                 $width = $this->image->getWidth() < $this->width ? $this->image->getWidth() : $this->width;
                 $this->image->fit($width, $height, function ($constraint) {
                     /* @var $constraint \Intervention\Image\Constraint */
                     $constraint->aspectRatio();
                     $constraint->upsize();
                 });
             }
             return;
         }
         if ($this->fit === self::FIT_CLIP) {
             $this->image->resize($this->width, $this->height, function ($constraint) {
                 /* @var $constraint \Intervention\Image\Constraint */
                 $constraint->aspectRatio();
                 $constraint->upsize();
             });
             return;
         }
         if ($this->fit === self::FIT_SCALE) {
             $this->image->resize($this->width, $this->height);
             return;
         }
         if ($this->fit === self::FIT_CLAMP) {
             $this->image->resize($this->width, $this->height, function ($constraint) {
                 /* @var $constraint \Intervention\Image\Constraint */
                 $constraint->aspectRatio();
             });
         }
     }
 }
开发者ID:Monori,项目名称:imgback,代码行数:50,代码来源:ImageHandler.php

示例14: createVariation

 /**
  * {@inheritdoc}
  */
 public function createVariation(ImageFormat $output_format, $quality, ImageDimensions $dimensions = null, ImageCropDimensions $crop_dimensions = null)
 {
     try {
         $img = new InterventionImage($this->data);
     } catch (\Intervention\Image\Exception\InvalidImageDataStringException $e) {
         throw new BadImageException('Bad image data', 0, $e);
     } catch (\Intervention\Image\Exception\ImageNotFoundException $e) {
         throw new BadImageException('Not an image', 0, $e);
     }
     if ($dimensions) {
         if ($dimensions->getGrab()) {
             $img->grab($dimensions->getWidth(), $dimensions->getHeight());
         } else {
             $img->resize($dimensions->getWidth(), $dimensions->getHeight(), $dimensions->getMaintainRatio(), $dimensions->canUpscale());
         }
     }
     return $img->encode($output_format->key(), $quality);
 }
开发者ID:bravo3,项目名称:image-manager,代码行数:21,代码来源:InterventionEncoder.php

示例15: getDownscaledImage

 /**
  * Get downscaled image if size is higher than limit,
  * return original image if lower.
  *
  * @param  Image  $processImage
  * @return Image
  */
 protected function getDownscaledImage(Image $processImage)
 {
     // prevent possible upsizing
     $processImage->resize($this->maxPixelSize, $this->maxPixelSize, function (Constraint $constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     });
     return $processImage;
 }
开发者ID:QuangDang212,项目名称:roadiz,代码行数:16,代码来源:DownscaleImageManager.php


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