Inheritance: implements Grafika\ImageInterface
Beispiel #1
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function draw($image)
 {
     $strokeColor = new \ImagickPixel($this->getColor()->getHexString());
     $draw = new \ImagickDraw();
     $draw->setStrokeColor($strokeColor);
     $draw->setStrokeWidth($this->thickness);
     list($x1, $y1) = $this->point1;
     list($x2, $y2) = $this->point2;
     $draw->line($x1, $y1, $x2, $y2);
     $image->getCore()->drawImage($draw);
     return $image;
 }
Beispiel #2
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $size = $this->amount;
     $width = $image->getWidth();
     $height = $image->getHeight();
     $image->getCore()->scaleImage(max(1, $width / $size), max(1, $height / $size));
     $image->getCore()->scaleImage($width, $height);
     return $image;
 }
Beispiel #3
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     // normalize colorize levels
     $red = $this->normalizeLevel($this->red);
     $green = $this->normalizeLevel($this->green);
     $blue = $this->normalizeLevel($this->blue);
     $qrange = $image->getCore()->getQuantumRange();
     $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 $image;
 }
Beispiel #4
0
 /**
  * Resize helper function.
  *
  * @param Image $image
  * @param int $newWidth
  * @param int $newHeight
  *
  * @return self
  * @throws \Exception
  */
 private function _resize(&$image, $newWidth, $newHeight)
 {
     if ('GIF' == $image->getType()) {
         // Animated image. Eg. GIF
         $imagick = $image->getCore()->coalesceImages();
         foreach ($imagick as $frame) {
             $frame->resizeImage($newWidth, $newHeight, \Imagick::FILTER_BOX, 1, false);
             $frame->setImagePage($newWidth, $newHeight, 0, 0);
         }
         // Assign new image with frames
         $image = new Image($imagick->deconstructImages(), $image->getImageFile(), $newWidth, $newHeight, $image->getType());
     } else {
         // Single frame image. Eg. JPEG, PNG
         $image->getCore()->resizeImage($newWidth, $newHeight, \Imagick::FILTER_LANCZOS, 1, false);
         // Assign new image
         $image = new Image($image->getCore(), $image->getImageFile(), $newWidth, $newHeight, $image->getType());
     }
 }
Beispiel #5
0
 /**
  * Create a blank image.
  *
  * @param int $width Width of image in pixels.
  * @param int $height Height of image in pixels.
  *
  * @return ImageInterface
  * @throws \Exception
  */
 public static function createBlankImage($width = 1, $height = 1)
 {
     $editorName = self::detectAvailableEditor();
     if ('Imagick' === $editorName) {
         return ImagickImage::createBlank($width, $height);
     } else {
         return GdImage::createBlank($width, $height);
     }
 }
Beispiel #6
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $image->getCore()->modulateImage(100 + $this->amount, 100, 100);
     return $image;
 }
Beispiel #7
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $image->getCore()->sigmoidalContrastImage($this->amount > 0, $this->amount / 4, 0);
     return $image;
 }
Beispiel #8
0
 /**
  * Dither by applying a threshold map.
  *
  * @param Image $image
  *
  * @return Image
  */
 private function ordered($image)
 {
     // Localize vars
     $width = $image->getWidth();
     $height = $image->getHeight();
     $thresholdMap = array(array(15, 135, 45, 165), array(195, 75, 225, 105), array(60, 180, 30, 150), array(240, 120, 210, 90));
     // Loop using image1
     $pixelIterator = $image->getCore()->getPixelIterator();
     foreach ($pixelIterator as $y => $rows) {
         /* Loop through pixel rows */
         foreach ($rows as $x => $px) {
             /* Loop through the pixels in the row (columns) */
             /**
              * @var $px \ImagickPixel */
             $rgba = $px->getColor();
             $gray = round($rgba['r'] * 0.3 + $rgba['g'] * 0.59 + $rgba['b'] * 0.11);
             $threshold = $thresholdMap[$x % 4][$y % 4];
             $oldPixel = ($gray + $threshold) / 2;
             if ($oldPixel <= 127) {
                 // Determine if black or white. Also has the benefit of clipping excess value
                 $newPixel = 0;
             } else {
                 $newPixel = 255;
             }
             // Current pixel
             $px->setColor("rgb({$newPixel},{$newPixel},{$newPixel})");
         }
         $pixelIterator->syncIterator();
         /* Sync the iterator, this is important to do on each iteration */
     }
     $type = $image->getType();
     $file = $image->getImageFile();
     $image = $image->getCore();
     return new Image($image, $file, $width, $height, $type);
     // Create new image with updated core
 }
Beispiel #9
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $image->getCore()->unsharpMaskImage(1, 1, $this->amount / 6.25, 0);
     return $image;
 }
Beispiel #10
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $image->getCore()->negateImage(false);
     return $image;
 }
Beispiel #11
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $image->getCore()->modulateImage(100, 0, 100);
     return $image;
 }
Beispiel #12
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $image->getCore()->gammaImage($this->amount);
     return $image;
 }
Beispiel #13
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $image->getCore()->blurImage(1 * $this->amount, 0.5 * $this->amount);
     return $image;
 }
Beispiel #14
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $pixels = array();
     $finalPx = array();
     // Localize vars
     $width = $image->getWidth();
     $height = $image->getHeight();
     // Loop
     $pixelIterator = $image->getCore()->getPixelIterator();
     foreach ($pixelIterator as $y => $rows) {
         /* Loop through pixel rows */
         foreach ($rows as $x => $px) {
             /* Loop through the pixels in the row (columns) */
             // row 0
             if ($x > 0 and $y > 0) {
                 $matrix[0][0] = $this->getColor($px, $pixels, $x - 1, $y - 1);
             } else {
                 $matrix[0][0] = $this->getColor($px, $pixels, $x, $y);
             }
             if ($y > 0) {
                 $matrix[1][0] = $this->getColor($px, $pixels, $x, $y - 1);
             } else {
                 $matrix[1][0] = $this->getColor($px, $pixels, $x, $y);
             }
             if ($x + 1 < $width and $y > 0) {
                 $matrix[2][0] = $this->getColor($px, $pixels, $x + 1, $y - 1);
             } else {
                 $matrix[2][0] = $this->getColor($px, $pixels, $x, $y);
             }
             // row 1
             if ($x > 0) {
                 $matrix[0][1] = $this->getColor($px, $pixels, $x - 1, $y);
             } else {
                 $matrix[0][1] = $this->getColor($px, $pixels, $x, $y);
             }
             if ($x + 1 < $width) {
                 $matrix[2][1] = $this->getColor($px, $pixels, $x + 1, $y);
             } else {
                 $matrix[2][1] = $this->getColor($px, $pixels, $x, $y);
             }
             // row 1
             if ($x > 0 and $y + 1 < $height) {
                 $matrix[0][2] = $this->getColor($px, $pixels, $x - 1, $y + 1);
             } else {
                 $matrix[0][2] = $this->getColor($px, $pixels, $x, $y);
             }
             if ($y + 1 < $height) {
                 $matrix[1][2] = $this->getColor($px, $pixels, $x, $y + 1);
             } else {
                 $matrix[1][2] = $this->getColor($px, $pixels, $x, $y);
             }
             if ($x + 1 < $width and $y + 1 < $height) {
                 $matrix[2][2] = $this->getColor($px, $pixels, $x + 1, $y + 1);
             } else {
                 $matrix[2][2] = $this->getColor($px, $pixels, $x, $y);
             }
             $edge = $this->convolve($matrix);
             $edge = intval($edge / 2);
             if ($edge > 255) {
                 $edge = 255;
             }
             /**
              * @var \ImagickPixel $px Current pixel.
              */
             $finalPx[] = $edge;
             // R
             $finalPx[] = $edge;
             // G
             $finalPx[] = $edge;
             // B
         }
         $pixelIterator->syncIterator();
         /* Sync the iterator, this is important to do on each iteration */
     }
     $new = new \Imagick();
     $new->newImage($width, $height, new \ImagickPixel('black'));
     /* Import the pixels into image.
        width * height * strlen("RGB") must match count($pixels) */
     $new->importImagePixels(0, 0, $width, $height, "RGB", \Imagick::PIXEL_CHAR, $finalPx);
     $type = $image->getType();
     $file = $image->getImageFile();
     return new Image($new, $file, $width, $height, $type);
     // Create new image with updated core
 }