コード例 #1
1
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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();
     // build 2 color alpha mask from original alpha
     $alpha = clone $image->getCore();
     $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
     $alpha->transparentPaintImage('#ffffff', 0, 0, false);
     $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
     $alpha->negateImage(false);
     if ($matte) {
         // get matte color
         $mattecolor = $image->getDriver()->parseColor($matte)->getPixel();
         // create matte image
         $canvas = new \Imagick();
         $canvas->newImage($size->width, $size->height, $mattecolor, 'png');
         // lower colors of original and copy to matte
         $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
         $canvas->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0);
         // copy new alpha to canvas
         $canvas->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
         // replace core
         $image->setCore($canvas);
     } else {
         $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
         $image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
     }
     return true;
 }
コード例 #3
0
 /**
  * Applies a pixelation effect to a given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $size = $this->argument(0)->type('integer')->value(10);
     $width = $image->getWidth();
     $height = $image->getHeight();
     $image->getCore()->scaleImage(max(1, $width / $size), max(1, $height / $size));
     $image->getCore()->scaleImage($width, $height);
     return true;
 }
コード例 #4
0
 /**
  * Mirrors an image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $mode = $this->argument(0)->value('h');
     if (in_array(strtolower($mode), array(2, 'v', 'vert', 'vertical'))) {
         // flip vertical
         return $image->getCore()->flipImage();
     } else {
         // flip horizontal
         return $image->getCore()->flopImage();
     }
 }
コード例 #5
0
 /**
  * Crops and resized an image at the same time
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('integer')->required()->value();
     $height = $this->argument(1)->type('integer')->value($width);
     // calculate size
     $fitted = $image->getSize()->fit(new Size($width, $height));
     // crop image
     $image->getCore()->cropImage($fitted->width, $fitted->height, $fitted->pivot->x, $fitted->pivot->y);
     // resize image
     $image->getCore()->resizeImage($width, $height, \Imagick::FILTER_BOX, 1);
     $image->getCore()->setImagePage(0, 0, 0, 0);
     return true;
 }
コード例 #6
0
 /**
  * Read color information from a certain position
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $x = $this->argument(0)->type('integer')->required()->value();
     $y = $this->argument(1)->type('integer')->required()->value();
     $format = $this->argument(2)->type('string')->value('array');
     // pick color
     $color = imagecolorat($image->getCore(), $x, $y);
     if (!imageistruecolor($image->getCore())) {
         $color = imagecolorsforindex($image->getCore(), $color);
         $color['alpha'] = round(1 - $color['alpha'] / 127, 2);
     }
     $color = new Color($color);
     // format to output
     $this->setOutput($color->format($format));
     return true;
 }
コード例 #7
0
 /**
  * Changes balance of different RGB color channels
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $red = $this->argument(0)->between(-100, 100)->required()->value();
     $green = $this->argument(1)->between(-100, 100)->required()->value();
     $blue = $this->argument(2)->between(-100, 100)->required()->value();
     // normalize colorize levels
     $red = $this->normalizeLevel($red);
     $green = $this->normalizeLevel($green);
     $blue = $this->normalizeLevel($blue);
     $qrange = $image->getCore()->getQuantumRange();
     // apply
     $image->getCore()->levelImage(0, $red, $qrange['quantumRangeLong'], \Imagick::CHANNEL_RED);
     $image->getCore()->levelImage(0, $green, $qrange['quantumRangeLong'], \Imagick::CHANNEL_GREEN);
     $image->getCore()->levelImage(0, $blue, $qrange['quantumRangeLong'], \Imagick::CHANNEL_BLUE);
     return true;
 }
コード例 #8
0
 /**
  * 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;
 }
コード例 #9
0
 /**
  * Insert another image into given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $source = $this->argument(0)->required()->value();
     $position = $this->argument(1)->type('string')->value();
     $x = $this->argument(2)->type('integer')->value(0);
     $y = $this->argument(3)->type('integer')->value(0);
     // build watermark
     $watermark = $image->getDriver()->init($source);
     // define insertion point
     $image_size = $image->getSize()->align($position, $x, $y);
     $watermark_size = $watermark->getSize()->align($position);
     $target = $image_size->relativePosition($watermark_size);
     // insert image at position
     imagealphablending($image->getCore(), true);
     return imagecopy($image->getCore(), $watermark->getCore(), $target->x, $target->y, 0, 0, $watermark_size->width, $watermark_size->height);
 }
コード例 #10
0
 /**
  * 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('integer')->required()->value();
     $y = $this->argument(2)->type('integer')->required()->value();
     return imagesetpixel($image->getCore(), $x, $y, $color->getInt());
 }
コード例 #11
0
 /**
  * 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;
 }
コード例 #12
0
 /**
  * Resizes image boundaries
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('integer')->required()->value();
     $height = $this->argument(1)->type('integer')->required()->value();
     $anchor = $this->argument(2)->value('center');
     $relative = $this->argument(3)->type('boolean')->value();
     $bgcolor = $this->argument(4)->value();
     $original_width = $image->getWidth();
     $original_height = $image->getHeight();
     // check of only width or height is set
     $width = is_null($width) ? $original_width : intval($width);
     $height = is_null($height) ? $original_height : intval($height);
     // check on relative width/height
     if ($relative) {
         $width = $original_width + $width;
         $height = $original_height + $height;
     }
     // check for negative width/height
     $width = $width <= 0 ? $width + $original_width : $width;
     $height = $height <= 0 ? $height + $original_height : $height;
     // create new canvas
     $canvas = $image->getDriver()->newImage($width, $height, $bgcolor);
     // set copy position
     $canvas_size = $canvas->getSize()->align($anchor);
     $image_size = $image->getSize()->align($anchor);
     $canvas_pos = $image_size->relativePosition($canvas_size);
     $image_pos = $canvas_size->relativePosition($image_size);
     if ($width <= $original_width) {
         $dst_x = 0;
         $src_x = $canvas_pos->x;
         $src_w = $canvas_size->width;
     } else {
         $dst_x = $image_pos->x;
         $src_x = 0;
         $src_w = $original_width;
     }
     if ($height <= $original_height) {
         $dst_y = 0;
         $src_y = $canvas_pos->y;
         $src_h = $canvas_size->height;
     } else {
         $dst_y = $image_pos->y;
         $src_y = 0;
         $src_h = $original_height;
     }
     // make image area transparent to keep transparency
     // even if background-color is set
     $transparent = imagecolorallocatealpha($canvas->getCore(), 255, 255, 255, 127);
     imagealphablending($canvas->getCore(), false);
     // do not blend / just overwrite
     imagefilledrectangle($canvas->getCore(), $dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1, $transparent);
     // copy image into new canvas
     imagecopy($canvas->getCore(), $image->getCore(), $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
     // set new core to canvas
     $image->setCore($canvas->getCore());
     return true;
 }
コード例 #13
0
 /**
  * Rotates image counter clockwise
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $angle = $this->argument(0)->type('numeric')->required()->value();
     $color = $this->argument(1)->value();
     $color = new Color($color);
     // rotate image
     $image->setCore(imagerotate($image->getCore(), $angle, $color->getInt()));
     return true;
 }
コード例 #14
0
ファイル: Driver.php プロジェクト: Roc4rdho/app
 /**
  * Creates new image instance
  *
  * @param  integer $width
  * @param  integer $height
  * @param  string  $background
  * @return \Intervention\Image\Image
  */
 public function newImage($width, $height, $background = null)
 {
     // create empty resource
     $core = imagecreatetruecolor($width, $height);
     $image = new \Intervention\Image\Image(new static(), $core);
     // set background color
     $background = new Color($background);
     imagefill($image->getCore(), 0, 0, $background->getInt());
     return $image;
 }
コード例 #15
0
 /**
  * Toggles interlaced encoding mode
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $mode = $this->argument(0)->type('bool')->value(true);
     if ($mode) {
         $mode = \Imagick::INTERLACE_LINE;
     } else {
         $mode = \Imagick::INTERLACE_NO;
     }
     $image->getCore()->setInterlaceScheme($mode);
     return true;
 }
コード例 #16
0
 /**
  * Resets given image to its backup state
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     if (is_resource($backup = $image->getBackup())) {
         // destroy old resource
         imagedestroy($image->getCore());
         // reset to new resource
         $image->setCore($backup);
         return true;
     }
     throw new \Intervention\Image\Exception\RuntimeException("Backup not available. Call backup() before reset().");
 }
コード例 #17
0
 /**
  * Crop an image instance
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('integer')->required()->value();
     $height = $this->argument(1)->type('integer')->required()->value();
     $x = $this->argument(2)->type('integer')->value();
     $y = $this->argument(3)->type('integer')->value();
     if (is_null($width) || is_null($height)) {
         throw new \Intervention\Image\Exception\InvalidArgumentException("Width and height of cutout needs to be defined.");
     }
     $cropped = new Size($width, $height);
     $position = new Point($x, $y);
     // align boxes
     if (is_null($x) && is_null($y)) {
         $position = $image->getSize()->align('center')->relativePosition($cropped->align('center'));
     }
     // crop image core
     $image->getCore()->cropImage($cropped->width, $cropped->height, $position->x, $position->y);
     $image->getCore()->setImagePage(0, 0, 0, 0);
     return true;
 }
コード例 #18
0
 /**
  * Read color information from a certain position
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $x = $this->argument(0)->type('integer')->required()->value();
     $y = $this->argument(1)->type('integer')->required()->value();
     $format = $this->argument(2)->type('string')->value('array');
     // pick color
     $color = new Color($image->getCore()->getImagePixelColor($x, $y));
     // format to output
     $this->setOutput($color->format($format));
     return true;
 }
コード例 #19
0
 /**
  * Resizes image dimensions
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->value();
     $height = $this->argument(1)->value();
     $constraints = $this->argument(2)->type('closure')->value();
     // resize box
     $resized = $image->getSize()->resize($width, $height, $constraints);
     // modify image
     $image->getCore()->resizeImage($resized->getWidth(), $resized->getHeight(), \Imagick::FILTER_BOX, 1);
     return true;
 }
コード例 #20
0
 /**
  * Saves a backups of current state of image core
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     // clone current image resource
     $size = $image->getSize();
     $clone = imagecreatetruecolor($size->width, $size->height);
     imagealphablending($clone, false);
     imagesavealpha($clone, true);
     imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
     $image->setBackup($clone);
     return true;
 }
コード例 #21
0
 /**
  * Sharpen image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $amount = $this->argument(0)->between(0, 100)->value(10);
     // build matrix
     $min = $amount >= 10 ? $amount * -0.01 : 0;
     $max = $amount * -0.025;
     $abs = (4 * $min + 4 * $max) * -1 + 1;
     $div = 1;
     $matrix = array(array($min, $max, $min), array($max, $abs, $max), array($min, $max, $min));
     // apply the matrix
     return imageconvolution($image->getCore(), $matrix, $div, 0);
 }
コード例 #22
0
 /**
  * Resets given image to its backup state
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $backup = $image->getBackup();
     if ($backup instanceof \Imagick) {
         // destroy old core
         $image->getCore()->clear();
         // reset to new resource
         $image->setCore($backup);
         return true;
     }
     throw new \Intervention\Image\Exception\RuntimeException("Backup not available. Call backup() before reset().");
 }
コード例 #23
0
 /**
  * Changes balance of different RGB color channels
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $red = $this->argument(0)->between(-100, 100)->required()->value();
     $green = $this->argument(1)->between(-100, 100)->required()->value();
     $blue = $this->argument(2)->between(-100, 100)->required()->value();
     // normalize colorize levels
     $red = round($red * 2.55);
     $green = round($green * 2.55);
     $blue = round($blue * 2.55);
     // apply filter
     return imagefilter($image->getCore(), IMG_FILTER_COLORIZE, $red, $green, $blue);
 }
コード例 #24
0
 /**
  * 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('integer')->required()->value();
     $y = $this->argument(2)->type('integer')->required()->value();
     // prepare pixel
     $draw = new \ImagickDraw();
     $draw->setFillColor($color->getPixel());
     $draw->point($x, $y);
     // apply pixel
     return $image->getCore()->drawImage($draw);
 }
コード例 #25
0
 /**
  * Fills image with color or pattern
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $filling = $this->argument(0)->value();
     $x = $this->argument(1)->type('integer')->value();
     $y = $this->argument(2)->type('integer')->value();
     $width = $image->getWidth();
     $height = $image->getHeight();
     $resource = $image->getCore();
     try {
         // set image tile filling
         $source = new Decoder();
         $tile = $source->init($filling);
         imagesettile($image->getCore(), $tile->getCore());
         $filling = IMG_COLOR_TILED;
     } catch (\Intervention\Image\Exception\NotReadableException $e) {
         // set solid color filling
         $color = new Color($filling);
         $filling = $color->getInt();
     }
     imagealphablending($resource, true);
     if (is_int($x) && is_int($y)) {
         // resource should be visible through transparency
         $base = $image->getDriver()->newImage($width, $height)->getCore();
         imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);
         // floodfill if exact position is defined
         imagefill($resource, $x, $y, $filling);
         // copy filled original over base
         imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);
         // set base as new resource-core
         $image->setCore($base);
         imagedestroy($resource);
     } else {
         // fill whole image otherwise
         imagefilledrectangle($resource, 0, 0, $width - 1, $height - 1, $filling);
     }
     isset($tile) ? imagedestroy($tile->getCore()) : null;
     return true;
 }
コード例 #26
0
 /**
  * Insert another image into given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $source = $this->argument(0)->required()->value();
     $position = $this->argument(1)->type('string')->value();
     $x = $this->argument(2)->type('integer')->value(0);
     $y = $this->argument(3)->type('integer')->value(0);
     // build watermark
     $watermark = $image->getDriver()->init($source);
     // define insertion point
     $image_size = $image->getSize()->align($position, $x, $y);
     $watermark_size = $watermark->getSize()->align($position);
     $target = $image_size->relativePosition($watermark_size);
     // insert image at position
     return $image->getCore()->compositeImage($watermark->getCore(), \Imagick::COMPOSITE_DEFAULT, $target->x, $target->y);
 }
コード例 #27
0
 /**
  * Changes image brightness
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $level = $this->argument(0)->between(-100, 100)->required()->value();
     return imagefilter($image->getCore(), IMG_FILTER_BRIGHTNESS, $level * 2.55);
 }
コード例 #28
0
 /**
  * Resizes image boundaries
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('integer')->required()->value();
     $height = $this->argument(1)->type('integer')->required()->value();
     $anchor = $this->argument(2)->value('center');
     $relative = $this->argument(3)->type('boolean')->value();
     $bgcolor = $this->argument(4)->value();
     $original_width = $image->getWidth();
     $original_height = $image->getHeight();
     // check of only width or height is set
     $width = is_null($width) ? $original_width : intval($width);
     $height = is_null($height) ? $original_height : intval($height);
     // check on relative width/height
     if ($relative) {
         $width = $original_width + $width;
         $height = $original_height + $height;
     }
     // check for negative width/height
     $width = $width <= 0 ? $width + $original_width : $width;
     $height = $height <= 0 ? $height + $original_height : $height;
     // create new canvas
     $canvas = $image->getDriver()->newImage($width, $height, $bgcolor);
     // set copy position
     $canvas_size = $canvas->getSize()->align($anchor);
     $image_size = $image->getSize()->align($anchor);
     $canvas_pos = $image_size->relativePosition($canvas_size);
     $image_pos = $canvas_size->relativePosition($image_size);
     if ($width <= $original_width) {
         $dst_x = 0;
         $src_x = $canvas_pos->x;
         $src_w = $canvas_size->width;
     } else {
         $dst_x = $image_pos->x;
         $src_x = 0;
         $src_w = $original_width;
     }
     if ($height <= $original_height) {
         $dst_y = 0;
         $src_y = $canvas_pos->y;
         $src_h = $canvas_size->height;
     } else {
         $dst_y = $image_pos->y;
         $src_y = 0;
         $src_h = $original_height;
     }
     // make image area transparent to keep transparency
     // even if background-color is set
     $rect = new \ImagickDraw();
     $fill = $canvas->pickColor(0, 0, 'hex');
     $fill = $fill == '#ff0000' ? '#00ff00' : '#ff0000';
     $rect->setFillColor($fill);
     $rect->rectangle($dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1);
     $canvas->getCore()->drawImage($rect);
     $canvas->getCore()->transparentPaintImage($fill, 0, 0, false);
     // copy image into new canvas
     $image->getCore()->cropImage($src_w, $src_h, $src_x, $src_y);
     $canvas->getCore()->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, $dst_x, $dst_y);
     $canvas->getCore()->setImagePage(0, 0, 0, 0);
     // set new core to canvas
     $image->setCore($canvas->getCore());
     return true;
 }
コード例 #29
0
 /**
  * Turns an image into a greyscale version
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     return imagefilter($image->getCore(), IMG_FILTER_GRAYSCALE);
 }
コード例 #30
0
 /**
  * Applies gamma correction to a given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $gamma = $this->argument(0)->type('numeric')->required()->value();
     return $image->getCore()->gammaImage($gamma);
 }