From 5e078ed4c4d317e60ba6b8479721c9abf4829ad4 Mon Sep 17 00:00:00 2001 From: "David D." Date: Fri, 1 Mar 2013 16:17:34 -0700 Subject: [PATCH] Update Image.php --- src/Intervention/Image/Image.php | 61 ++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 3b141a06..563155d4 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -314,23 +314,35 @@ class Image $height = array_key_exists('height', $dimensions) ? intval($dimensions['height']) : null; return $this->resize($width, $height, true); } - + /** - * Crop an image + * Crop the current image + * + * @param integer $width + * @param integer $height + * @param integer $pos_x + * @param integer $pos_y * - * @param integer $src_x - * @param integer $src_y - * @param integer $src_w - * @param integer $src_h * @return Image */ - public function crop($src_x , $src_y , $src_w , $src_h) + public function crop($width, $height, $pos_x = null, $pos_y = null) { - if (is_null($src_x) || is_null($src_y) || is_null($src_w) || is_null($src_h)) { - throw new Exception('x, y, width and height needs to be defined'); + $width = is_numeric($width) ? intval($width) : null; + $height = is_numeric($height) ? intval($height) : null; + $pos_x = is_numeric($pos_x) ? intval($pos_x) : null; + $pos_y = is_numeric($pos_y) ? intval($pos_y) : null; + + if (is_null($pos_x) && is_null($pos_y)) { + // center position of width/height rectangle + $pos_x = floor(($this->width - intval($width)) / 2); + $pos_y = floor(($this->height - intval($height)) / 2); } - $this->modify(0, 0, $src_x , $src_y, $src_w, $src_h, $src_w, $src_h); - return $this; + + if (is_null($width) || is_null($height)) { + throw new Exception('width and height of cutout needs to be defined'); + } + + return $this->modify(0, 0, $pos_x , $pos_y, $width, $height, $width, $height); } /** @@ -410,6 +422,21 @@ class Image return $this; } + /** + * Rotate image with given angle + * + * @param float $angle + * @param string $color + * @param int $ignore_transparent + * @return Image + */ + public function rotate($angle = 0, $color = '#000000', $ignore_transparent = 0) + { + $this->resource = imagerotate($this->resource, $angle, $this->parseColor($color), $ignore_transparent); + + return $this; + } + /** * Fill image with given hexadecimal color at position x,y * @@ -614,6 +641,18 @@ class Image return $this; } + /** + * Invert colors of current image + * + * @return Image + */ + public function invert() + { + imagefilter($this->resource, IMG_FILTER_NEGATE); + + return $this; + } + /** * Reset to original image resource *