1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-19 04:01:30 +02:00

added optional constraint parameter to widen and heighten

This commit is contained in:
Oliver Vogel
2014-08-31 12:16:28 +02:00
parent 45e1be89c5
commit 41266db66d
6 changed files with 68 additions and 4 deletions

View File

@@ -13,11 +13,14 @@ class HeightenCommand extends ResizeCommand
public function execute($image)
{
$height = $this->argument(0)->type('digit')->required()->value();
$additionalConstraints = $this->argument(1)->type('closure')->value();
$this->arguments[0] = null;
$this->arguments[1] = $height;
$this->arguments[2] = function ($constraint) {
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
$constraint->aspectRatio();
if(is_callable($additionalConstraints))
$additionalConstraints($constraint);
};
return parent::execute($image);

View File

@@ -13,11 +13,14 @@ class WidenCommand extends ResizeCommand
public function execute($image)
{
$width = $this->argument(0)->type('digit')->required()->value();
$additionalConstraints = $this->argument(1)->type('closure')->value();
$this->arguments[0] = $width;
$this->arguments[1] = null;
$this->arguments[2] = function ($constraint) {
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
$constraint->aspectRatio();
if(is_callable($additionalConstraints))
$additionalConstraints($constraint);
};
return parent::execute($image);

View File

@@ -13,11 +13,14 @@ class HeightenCommand extends ResizeCommand
public function execute($image)
{
$height = $this->argument(0)->type('digit')->required()->value();
$additionalConstraints = $this->argument(1)->type('closure')->value();
$this->arguments[0] = null;
$this->arguments[1] = $height;
$this->arguments[2] = function ($constraint) {
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
$constraint->aspectRatio();
if(is_callable($additionalConstraints))
$additionalConstraints($constraint);
};
return parent::execute($image);

View File

@@ -13,11 +13,14 @@ class WidenCommand extends ResizeCommand
public function execute($image)
{
$width = $this->argument(0)->type('digit')->required()->value();
$additionalConstraints = $this->argument(1)->type('closure')->value();
$this->arguments[0] = $width;
$this->arguments[1] = null;
$this->arguments[2] = function ($constraint) {
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
$constraint->aspectRatio();
if(is_callable($additionalConstraints))
$additionalConstraints($constraint);
};
return parent::execute($image);

View File

@@ -195,6 +195,19 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
$this->assertTransparentPosition($img, 60, 0);
}
public function testWidenImageWithConstraint()
{
$img = $this->manager()->make('tests/images/tile.png');
$img->widen(100, function ($constraint) {$constraint->upsize();});
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertInternalType('resource', $img->getCore());
$this->assertInternalType('int', $img->getWidth());
$this->assertInternalType('int', $img->getHeight());
$this->assertEquals(16, $img->getWidth());
$this->assertEquals(16, $img->getHeight());
$this->assertTransparentPosition($img, 8, 0);
}
public function testHeightenImage()
{
$img = $this->manager()->make('tests/images/tile.png');
@@ -208,6 +221,19 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
$this->assertTransparentPosition($img, 60, 0);
}
public function testHeightenImageWithConstraint()
{
$img = $this->manager()->make('tests/images/tile.png');
$img->heighten(100, function ($constraint) {$constraint->upsize();});
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertInternalType('resource', $img->getCore());
$this->assertInternalType('int', $img->getWidth());
$this->assertInternalType('int', $img->getHeight());
$this->assertEquals(16, $img->getWidth());
$this->assertEquals(16, $img->getHeight());
$this->assertTransparentPosition($img, 8, 0);
}
public function testResizeCanvasCenter()
{
$img = $this->manager()->make('tests/images/tile.png');

View File

@@ -197,6 +197,19 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
$this->assertTransparentPosition($img, 60, 0);
}
public function testWidenImageWithConstraint()
{
$img = $this->manager()->make('tests/images/tile.png');
$img->widen(100, function ($constraint) {$constraint->upsize();});
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertInstanceOf('Imagick', $img->getCore());
$this->assertInternalType('int', $img->getWidth());
$this->assertInternalType('int', $img->getHeight());
$this->assertEquals(16, $img->getWidth());
$this->assertEquals(16, $img->getHeight());
$this->assertTransparentPosition($img, 8, 0);
}
public function testHeightenImage()
{
$img = $this->manager()->make('tests/images/tile.png');
@@ -210,6 +223,19 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
$this->assertTransparentPosition($img, 60, 0);
}
public function testHeightenImageWithConstraint()
{
$img = $this->manager()->make('tests/images/tile.png');
$img->heighten(100, function ($constraint) {$constraint->upsize();});
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertInstanceOf('Imagick', $img->getCore());
$this->assertInternalType('int', $img->getWidth());
$this->assertInternalType('int', $img->getHeight());
$this->assertEquals(16, $img->getWidth());
$this->assertEquals(16, $img->getHeight());
$this->assertTransparentPosition($img, 8, 0);
}
public function testResizeCanvasCenter()
{
$img = $this->manager()->make('tests/images/tile.png');