Inheritance: implements Grafika\ImageInterface
Beispiel #1
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     for ($i = 0; $i < $this->amount; $i++) {
         imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR);
     }
     return $image;
 }
Beispiel #2
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function draw($image)
 {
     list($x1, $y1) = $this->point1;
     list($x2, $y2) = $this->point2;
     list($r, $g, $b) = $this->color->getRgb();
     $color = imagecolorallocate($image->getCore(), $r, $g, $b);
     if (function_exists('imageantialias')) {
         // Not available on some if PHP is not precompiled with it even if GD is enabled
         imageantialias($image->getCore(), true);
     }
     imageline($image->getCore(), $x1, $y1, $x2, $y2, $color);
     return $image;
 }
Beispiel #3
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     $amount = $this->amount;
     // 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
     imageconvolution($image->getCore(), $matrix, $div, 0);
     return $image;
 }
Beispiel #4
0
 /**
  * Crop based on entropy.
  *
  * @param Image $oldImage
  * @param $cropW
  * @param $cropH
  *
  * @return array
  */
 private function _smartCrop($oldImage, $cropW, $cropH)
 {
     $image = clone $oldImage;
     $this->resizeFit($image, 30, 30);
     $origW = $oldImage->getWidth();
     $origH = $oldImage->getHeight();
     $resizeW = $image->getWidth();
     $resizeH = $image->getHeight();
     $smallCropW = round($resizeW / $origW * $cropW);
     $smallCropH = round($resizeH / $origH * $cropH);
     $step = 1;
     for ($y = 0; $y < $resizeH - $smallCropH; $y += $step) {
         for ($x = 0; $x < $resizeW - $smallCropW; $x += $step) {
             $hist[$x . '-' . $y] = $this->_entropy($image->histogram(array(array($x, $y), array($smallCropW, $smallCropH))));
         }
         if ($resizeW - $smallCropW <= 0) {
             $hist['0-' . $y] = $this->_entropy($image->histogram(array(array(0, 0), array($smallCropW, $smallCropH))));
         }
     }
     if ($resizeH - $smallCropH <= 0) {
         $hist['0-0'] = $this->_entropy($image->histogram(array(array(0, 0), array($smallCropW, $smallCropH))));
     }
     asort($hist);
     end($hist);
     $pos = key($hist);
     // last key
     list($x, $y) = explode('-', $pos);
     $x = round($x * ($origW / $resizeW));
     $y = round($y * ($origH / $resizeH));
     return array($x, $y);
 }
Beispiel #5
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     imagefilter($image->getCore(), IMG_FILTER_BRIGHTNESS, $this->amount * 2.55);
     return $image;
 }
Beispiel #6
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 #7
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     imagefilter($image->getCore(), IMG_FILTER_GRAYSCALE);
     return $image;
 }
Beispiel #8
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     imagefilter($image->getCore(), IMG_FILTER_COLORIZE, $this->red, $this->green, $this->blue);
     return $image;
 }
Beispiel #9
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     imagefilter($image->getCore(), IMG_FILTER_PIXELATE, $this->amount, true);
     return $image;
 }
Beispiel #10
0
 /**
  * Dither by applying a threshold map.
  *
  * @param Image $image
  *
  * @return Image
  */
 private function ordered($image)
 {
     // Localize vars
     $width = $image->getWidth();
     $height = $image->getHeight();
     $old = $image->getCore();
     $new = imagecreatetruecolor($width, $height);
     $thresholdMap = array(array(15, 135, 45, 165), array(195, 75, 225, 105), array(60, 180, 30, 150), array(240, 120, 210, 90));
     for ($y = 0; $y < $height; $y += 1) {
         for ($x = 0; $x < $width; $x += 1) {
             $color = imagecolorat($old, $x, $y);
             $r = $color >> 16 & 0xff;
             $g = $color >> 8 & 0xff;
             $b = $color & 0xff;
             $gray = round($r * 0.3 + $g * 0.59 + $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
             imagesetpixel($new, $x, $y, imagecolorallocate($new, $newPixel, $newPixel, $newPixel));
         }
     }
     imagedestroy($old);
     // Free resource
     // Create new image with updated core
     return new Image($new, $image->getImageFile(), $width, $height, $image->getType());
 }
Beispiel #11
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     // Localize vars
     $width = $image->getWidth();
     $height = $image->getHeight();
     $old = $image->getCore();
     $pixels = array();
     $new = imagecreatetruecolor($width, $height);
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             // row 0
             if ($x > 0 and $y > 0) {
                 $matrix[0][0] = $this->getColor($old, $pixels, $x - 1, $y - 1);
             } else {
                 $matrix[0][0] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($y > 0) {
                 $matrix[1][0] = $this->getColor($old, $pixels, $x, $y - 1);
             } else {
                 $matrix[1][0] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($x + 1 < $width and $y > 0) {
                 $matrix[2][0] = $this->getColor($old, $pixels, $x + 1, $y - 1);
             } else {
                 $matrix[2][0] = $this->getColor($old, $pixels, $x, $y);
             }
             // row 1
             if ($x > 0) {
                 $matrix[0][1] = $this->getColor($old, $pixels, $x - 1, $y);
             } else {
                 $matrix[0][1] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($x + 1 < $width) {
                 $matrix[2][1] = $this->getColor($old, $pixels, $x + 1, $y);
             } else {
                 $matrix[2][1] = $this->getColor($old, $pixels, $x, $y);
             }
             // row 1
             if ($x > 0 and $y + 1 < $height) {
                 $matrix[0][2] = $this->getColor($old, $pixels, $x - 1, $y + 1);
             } else {
                 $matrix[0][2] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($y + 1 < $height) {
                 $matrix[1][2] = $this->getColor($old, $pixels, $x, $y + 1);
             } else {
                 $matrix[1][2] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($x + 1 < $width and $y + 1 < $height) {
                 $matrix[2][2] = $this->getColor($old, $pixels, $x + 1, $y + 1);
             } else {
                 $matrix[2][2] = $this->getColor($old, $pixels, $x, $y);
             }
             $edge = $this->convolve($matrix);
             $edge = intval($edge / 2);
             if ($edge > 255) {
                 $edge = 255;
             }
             $color = imagecolorallocate($new, $edge, $edge, $edge);
             imagesetpixel($new, $x, $y, $color);
         }
     }
     imagedestroy($old);
     // Free resource
     // Create and return new image with updated core
     return new Image($new, $image->getImageFile(), $width, $height, $image->getType());
 }
Beispiel #12
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     imagefilter($image->getCore(), IMG_FILTER_CONTRAST, $this->amount * -1);
     return $image;
 }
Beispiel #13
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     imagegammacorrect($image->getCore(), 1, $this->amount);
     return $image;
 }