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