mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 17:19:50 +02:00
added runAction method
This commit is contained in:
@@ -1291,6 +1291,30 @@ class Image
|
|||||||
return $this;
|
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)
|
* Convert rgba alpha (0-1) value to gd value (0-127)
|
||||||
*
|
*
|
||||||
|
@@ -884,6 +884,28 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
@unlink($save_as);
|
@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()
|
public function testStringConversion()
|
||||||
{
|
{
|
||||||
$img = $this->getTestImage();
|
$img = $this->getTestImage();
|
||||||
|
Reference in New Issue
Block a user