/** * 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); }
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); } }
/** * @return string */ public function getAveragePixelColor() { $this->intervention->resize(1, 1); $color = substr($this->intervention->pickColor(0, 0, 'hex'), 1); $this->intervention->reset(); return $color; }
public function applyFilter(Image $image) { return $image->resize(150, 100, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode('jpg', 75); }
/** * @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); }
public function applyFilter(Image $image) { return $image->greyscale()->resize(150, 100, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); }
/** * 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; }
/** * 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; }
/** * 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; }
public function applyFilter(Image $image) { return $image->fit(1400, 700, function ($constraint) { //$constraint->aspectRatio(); //$constraint->upsize(); })->encode('jpg', 70); }
/** * 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; }
public function applyFilter(Image $image) { return $image->resize(420, 420, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
public function process(Image $image) { if ($this->request->query->has('fit') && !$this->request->query->has('width') && !$this->request->query->has('height') && 1 === preg_match('#^([0-9]+)[x\\:]([0-9]+)$#', $this->request->query->get('fit'), $fit)) { $image->fit($fit[1], $fit[2], function (Constraint $constraint) { $constraint->upsize(); }); } }
/** * Perform brightness image manipulation. * @param Request $request The request object. * @param Image $image The source image. * @return Image The manipulated image. */ public function run(Request $request, Image $image) { $brightness = $this->getBrightness($request->get('bri')); if ($brightness) { $image->brightness($brightness); } return $image; }
/** * Applies blur effect on image * * @param \Intervention\Image\Image $image * @return boolean */ public function execute($image) { $amount = $this->argument(0)->between(0, 100)->value(1); for ($i = 0; $i < intval($amount); $i++) { imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR); } return true; }
/** * Perform blur image manipulation. * @param Image $image The source image. * @return Image The manipulated image. */ public function run(Image $image) { $blur = $this->getBlur(); if ($blur !== null) { $image->blur($blur); } return $image; }
/** * Perform contrast image manipulation. * @param Request $request The request object. * @param Image $image The source image. * @return Image The manipulated image. */ public function run(Request $request, Image $image) { $contrast = $this->getContrast($request->get('con')); if ($contrast) { $image->contrast($contrast); } return $image; }
/** * 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) { $gd = $image->getCore(); imagefilter($gd, IMG_FILTER_GRAYSCALE); imagefilter($gd, IMG_FILTER_COLORIZE, 60, 30, 0); $image->setCore($gd); return $image; }
/** * Perform orientation image manipulation. * @param Request $request The request object. * @param Image $image The source image. * @return Image The manipulated image. */ public function run(Request $request, Image $image) { $orientation = $this->getOrientation($request->get('or')); if ($orientation === 'auto') { return $image->orientate(); } return $image->rotate($orientation); }
/** * Draws one pixel to a given image * * @param \Intervention\Image\Image $image * @return boolean */ public function execute($image) { $color = $this->argument(0)->required()->value(); $color = new Color($color); $x = $this->argument(1)->type('digit')->required()->value(); $y = $this->argument(2)->type('digit')->required()->value(); return imagesetpixel($image->getCore(), $x, $y, $color->getInt()); }
/** * Perform blur image manipulation. * @param Request $request The request object. * @param Image $image The source image. * @return Image The manipulated image. */ public function run(Request $request, Image $image) { $blur = $this->getBlur($request->get('blur')); if ($blur) { $image->blur($blur); } return $image; }
public function run(Image $image) { $brightness = $this->getBrightness(); if ($brightness !== null) { $image->brightness($brightness); } return $image; }
/** * @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); }
/** * Perform gamma image manipulation. * @param Request $request The request object. * @param Image $image The source image. * @return Image The manipulated image. */ public function run(Request $request, Image $image) { $gamma = $this->getGamma($request->get('gam')); if ($gamma) { $image->gamma($gamma); } return $image; }
/** * Perform contrast image manipulation. * @param Image $image The source image. * @return Image The manipulated image. */ public function run(Image $image) { $contrast = $this->getContrast(); if ($contrast !== null) { $image->contrast($contrast); } return $image; }
/** * Removes all frames of an animation except one * * @param \Intervention\Image\Image $image * @return boolean */ public function execute($image) { $keepIndex = $this->argument(0)->type('int')->value(0); $container = new Container(); $container->add($image->getCore($keepIndex)); $image->setContainer($container); return true; }