1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 08:40:33 +02:00

Update Image.php

This commit is contained in:
David D.
2013-03-01 16:17:34 -07:00
parent 0341961b52
commit 5e078ed4c4

View File

@@ -316,21 +316,33 @@ class Image
}
/**
* 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
*