本文整理汇总了PHP中Intervention\Image\Image类的典型用法代码示例。如果您正苦于以下问题:PHP Image类的具体用法?PHP Image怎么用?PHP Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Perform orientation image manipulation.
* @param Image $image The source image.
* @return Image The manipulated image.
*/
public function run(Image $image)
{
$orientation = $this->getOrientation();
if ($orientation === 'auto') {
return $image->orientate();
}
return $image->rotate($orientation);
}
示例2: process
public function process(Image $image)
{
if ($this->request->query->has('progressive') || $this->request->query->has('interlace')) {
$process = $this->request->query->has('progressive') ? $this->request->query->get('progressive') : $this->request->query->get('interlace');
$image->interlace((bool) $process);
}
}
示例3: applyFilter
public function applyFilter(Image $image)
{
return $image->resize(150, 100, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('jpg', 75);
}
示例4: run
/**
* @param \Intervention\Image\Image $image
*
* @return void
*/
public function run(Image $image)
{
$callback = function (Constraint $constraint) {
$constraint->upsize();
};
$image->fit($this->width, $this->height, $callback, $this->position)->interlace($this->interlace);
}
示例5: applyFilter
public function applyFilter(Image $image)
{
return $image->greyscale()->resize(150, 100, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}
示例6: checkHeight
/**
* Check height first in resizing
*
* @param \Intervention\Image\Image $image
* @param integer $height
*
* @return integer
*/
private function checkHeight($image, $height)
{
if ($image->height() < $height) {
return $image->height();
}
return $height;
}
示例7: applyFilter
/**
* Applies filter effects to the given image
*
* @param Image\Image $image The image to filter.
*
* @return Image\Image The filtered image.
*/
public function applyFilter(Image\Image $image)
{
$image->fit(100, 100, function ($constraint) {
$constraint->upsize();
});
return $image;
}
示例8: execute
/**
* Reads size of given image instance in pixels
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
/** @var \Imagick $core */
$core = $image->getCore();
$this->setOutput(new Size($core->getImageWidth(), $core->getImageHeight()));
return true;
}
示例9: applyFilter
public function applyFilter(Image $image)
{
return $image->fit(1400, 700, function ($constraint) {
//$constraint->aspectRatio();
//$constraint->upsize();
})->encode('jpg', 70);
}
示例10: applyFilter
/**
* Applies filter effects to the given image
*
* @param Image\Image $image The image to filter.
*
* @return Image\Image The filtered image.
*
* @throws FilterException if the image filter algorithm fails.
*/
public function applyFilter(Image\Image $image)
{
if ($this->level <= 0) {
$gd = $image->getCore();
$width = imagesx($gd);
$height = imagesy($gd);
for ($x = 0; $x < $width; ++$x) {
for ($y = 0; $y < $height; ++$y) {
$rgba = imagecolorsforindex($gd, imagecolorat($gd, $x, $y));
$r = $rgba['red'];
$g = $rgba['green'];
$b = $rgba['blue'];
$a = $rgba['alpha'];
$level = $this->level * -1;
$max = max($r, $g, $b);
$avg = ($r + $g + $b) / 3;
$amt = abs($max - $avg) * 2 / 255 * $level / 100;
if ($r !== $max) {
$r += ($max - $r) * $amt;
}
if ($g !== $max) {
$g += ($max - $g) * $amt;
}
if ($b !== $max) {
$b += ($max - $b) * $amt;
}
imagesetpixel($gd, $x, $y, imagecolorallocatealpha($gd, $r, $g, $b, $a));
}
}
$image->setCore($gd);
} else {
$image->filter(new SaturateFilter($this->level));
}
return $image;
}
示例11: applyFilter
public function applyFilter(Image $image)
{
return $image->resize(420, 420, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}
示例12: execute
/**
* Reduces colors of a given image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$count = $this->argument(0)->value();
$matte = $this->argument(1)->value();
// get current image size
$size = $image->getSize();
// create empty canvas
$resource = imagecreatetruecolor($size->width, $size->height);
// define matte
if (is_null($matte)) {
$matte = imagecolorallocatealpha($resource, 255, 255, 255, 127);
} else {
$matte = $image->getDriver()->parseColor($matte)->getInt();
}
// fill with matte and copy original image
imagefill($resource, 0, 0, $matte);
// set transparency
imagecolortransparent($resource, $matte);
// copy original image
imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
if (is_numeric($count) && $count <= 256) {
// decrease colors
imagetruecolortopalette($resource, true, $count);
}
// set new resource
$image->setCore($resource);
return true;
}
示例13: execute
/**
* Saves a backups of current state of image core
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$backupName = $this->argument(0)->value();
// clone current image resource
$image->setBackup(clone $image->getCore(), $backupName);
return true;
}
示例14: execute
/**
* Applies an alpha mask to an image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$mask_source = $this->argument(0)->value();
$mask_w_alpha = $this->argument(1)->type('bool')->value(false);
// get imagick
$imagick = $image->getCore();
// build mask image from source
$mask = $image->getDriver()->init($mask_source);
// resize mask to size of current image (if necessary)
$image_size = $image->getSize();
if ($mask->getSize() != $image_size) {
$mask->resize($image_size->width, $image_size->height);
}
$imagick->setImageMatte(true);
if ($mask_w_alpha) {
// just mask with alpha map
$imagick->compositeImage($mask->getCore(), \Imagick::COMPOSITE_DSTIN, 0, 0);
} else {
// get alpha channel of original as greyscale image
$original_alpha = clone $imagick;
$original_alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
// use red channel from mask ask alpha
$mask_alpha = clone $mask->getCore();
$mask_alpha->compositeImage($mask->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0);
// $mask_alpha->setImageAlphaChannel(\Imagick::ALPHACHANNEL_DEACTIVATE);
$mask_alpha->separateImageChannel(\Imagick::CHANNEL_ALL);
// combine both alphas from original and mask
$original_alpha->compositeImage($mask_alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
// mask the image with the alpha combination
$imagick->compositeImage($original_alpha, \Imagick::COMPOSITE_DSTIN, 0, 0);
}
return true;
}
示例15: execute
/**
* Builds PSR7 stream based on image data. Method uses Guzzle PSR7
* implementation as easiest choice.
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$format = $this->argument(0)->value();
$quality = $this->argument(1)->between(0, 100)->value();
$this->setOutput(\GuzzleHttp\Psr7\stream_for($image->encode($format, $quality)->getEncoded()));
return true;
}