1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 09:10:21 +02:00

added runAction method

This commit is contained in:
Oliver Vogel
2013-03-24 17:13:17 +01:00
parent 1f8913cc33
commit 90480ebe52
2 changed files with 46 additions and 0 deletions

View File

@@ -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)
*

View File

@@ -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();