/**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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());
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
예제 #7
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;
 }
 /**
  * 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));
     // modify image
     $this->modify($image, 0, 0, $fitted->pivot->x, $fitted->pivot->y, $width, $height, $fitted->getWidth(), $fitted->getHeight());
     return true;
 }
 /**
  * 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;
 }
 /**
  * Correct image orientation according to Exif data
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     switch ($image->exif('Orientation')) {
         case 2:
             $image->flip();
             break;
         case 3:
             $image->rotate(180);
             break;
         case 4:
             $image->rotate(180)->flip();
             break;
         case 5:
             $image->rotate(270)->flip();
             break;
         case 6:
             $image->rotate(270);
             break;
         case 7:
             $image->rotate(90)->flip();
             break;
         case 8:
             $image->rotate(90);
             break;
     }
     return true;
 }
 /**
  * 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();
     }
 }
 /**
  * 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().");
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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
     $this->modify($image, 0, 0, 0, 0, $resized->getWidth(), $resized->getHeight(), $image->getWidth(), $image->getHeight());
     return true;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Calculates checksum of given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $colors = array();
     $size = $image->getSize();
     for ($x = 0; $x <= $size->width - 1; $x++) {
         for ($y = 0; $y <= $size->height - 1; $y++) {
             $colors[] = $image->pickColor($x, $y, 'array');
         }
     }
     $this->setOutput(md5(serialize($colors)));
     return true;
 }
 /**
  * Defines opacity of an image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $transparency = $this->argument(0)->between(0, 100)->required()->value();
     // get size of image
     $size = $image->getSize();
     // build temp alpha mask
     $mask_color = sprintf('rgba(0, 0, 0, %.1f)', $transparency / 100);
     $mask = $image->getDriver()->newImage($size->width, $size->height, $mask_color);
     // mask image
     $image->mask($mask->getCore(), true);
     return true;
 }
 /**
  * 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);
 }
 /**
  * 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().");
 }
 /**
  * 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);
 }
예제 #23
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;
 }
 /**
  * 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);
 }
 /**
  * Write text on given image
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $text = $this->argument(0)->required()->value();
     $x = $this->argument(1)->type('numeric')->value(0);
     $y = $this->argument(2)->type('numeric')->value(0);
     $callback = $this->argument(3)->type('closure')->value();
     $fontclassname = sprintf('\\Intervention\\Image\\%s\\Font', $image->getDriver()->getDriverName());
     $font = new $fontclassname($text);
     if ($callback instanceof Closure) {
         $callback($font);
     }
     $font->applyToImage($image, $x, $y);
     return true;
 }
 /**
  * Draws ellipse on given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('numeric')->required()->value();
     $height = $this->argument(1)->type('numeric')->required()->value();
     $x = $this->argument(2)->type('numeric')->required()->value();
     $y = $this->argument(3)->type('numeric')->required()->value();
     $callback = $this->argument(4)->type('closure')->value();
     $ellipse_classname = sprintf('\\Intervention\\Image\\%s\\Shapes\\EllipseShape', $image->getDriver()->getDriverName());
     $ellipse = new $ellipse_classname($width, $height);
     if ($callback instanceof Closure) {
         $callback($ellipse);
     }
     $ellipse->applyToImage($image, $x, $y);
     return true;
 }
 /**
  * Draws rectangle on given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $x1 = $this->argument(0)->type('numeric')->required()->value();
     $y1 = $this->argument(1)->type('numeric')->required()->value();
     $x2 = $this->argument(2)->type('numeric')->required()->value();
     $y2 = $this->argument(3)->type('numeric')->required()->value();
     $callback = $this->argument(4)->type('closure')->value();
     $rectangle_classname = sprintf('\\Intervention\\Image\\%s\\Shapes\\RectangleShape', $image->getDriver()->getDriverName());
     $rectangle = new $rectangle_classname($x1, $y1, $x2, $y2);
     if ($callback instanceof Closure) {
         $callback($rectangle);
     }
     $rectangle->applyToImage($image, $x1, $y1);
     return true;
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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);
 }