diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 281d4b5a..d5ef0af5 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -1291,6 +1291,30 @@ class Image return $this; } + /** + * Applies set of operations on current image + * + * @param Array $action + * @return Image + */ + public function runAction($action) + { + if (is_array($action) && count($action)) { + // apply action array on current image + foreach ($action as $method_name => $params) { + if (is_array($params)) { + call_user_method_array($method_name, $this, $params); + } else { + call_user_method($method_name, $this); + } + } + } else { + throw new Exception('Given action must be defined as an array.'); + } + + return $this; + } + /** * Convert rgba alpha (0-1) value to gd value (0-127) * diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 6405756c..7869cd37 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -884,6 +884,28 @@ class ImageTest extends PHPUnit_Framework_Testcase @unlink($save_as); } + public function testActionMethod() + { + // create test action + $make_thumbnail = array( + 'grab' => array(100, 100), + 'greyscale' => null, + 'flip' => array('h') + ); + + $img = Image::make('public/test.jpg'); + $img->runAction($make_thumbnail); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 100); + $this->assertEquals($img->height, 100); + $this->assertEquals('#cecece', $img->pickColor(0, 0, 'hex')); + $this->assertEquals('#adadad', $img->pickColor(0, 99, 'hex')); + $this->assertEquals('#ffffff', $img->pickColor(99, 0, 'hex')); + $this->assertEquals('#cdcdcd', $img->pickColor(99, 99, 'hex')); + } + public function testStringConversion() { $img = $this->getTestImage();