本文整理汇总了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;
}
示例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));
}
示例3: resizeImage
public function resizeImage($size)
{
$this->image->resize($size, null, function ($constraint) {
$constraint->aspectRatio();
});
return $this;
}
示例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;
}
示例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;
}
示例6: applyFilter
public function applyFilter(Image $image)
{
return $image->resize(420, 420, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}
示例7: applyFilter
public function applyFilter(Image $image)
{
return $image->resize(150, 100, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('jpg', 75);
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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();
});
}
}
}
示例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);
}
示例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;
}