mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 12:11:26 +02:00
added optional constraint parameter to widen and heighten
This commit is contained in:
@@ -13,11 +13,14 @@ class HeightenCommand extends ResizeCommand
|
|||||||
public function execute($image)
|
public function execute($image)
|
||||||
{
|
{
|
||||||
$height = $this->argument(0)->type('digit')->required()->value();
|
$height = $this->argument(0)->type('digit')->required()->value();
|
||||||
|
$additionalConstraints = $this->argument(1)->type('closure')->value();
|
||||||
|
|
||||||
$this->arguments[0] = null;
|
$this->arguments[0] = null;
|
||||||
$this->arguments[1] = $height;
|
$this->arguments[1] = $height;
|
||||||
$this->arguments[2] = function ($constraint) {
|
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
|
if(is_callable($additionalConstraints))
|
||||||
|
$additionalConstraints($constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return parent::execute($image);
|
return parent::execute($image);
|
||||||
|
@@ -13,11 +13,14 @@ class WidenCommand extends ResizeCommand
|
|||||||
public function execute($image)
|
public function execute($image)
|
||||||
{
|
{
|
||||||
$width = $this->argument(0)->type('digit')->required()->value();
|
$width = $this->argument(0)->type('digit')->required()->value();
|
||||||
|
$additionalConstraints = $this->argument(1)->type('closure')->value();
|
||||||
|
|
||||||
$this->arguments[0] = $width;
|
$this->arguments[0] = $width;
|
||||||
$this->arguments[1] = null;
|
$this->arguments[1] = null;
|
||||||
$this->arguments[2] = function ($constraint) {
|
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
|
if(is_callable($additionalConstraints))
|
||||||
|
$additionalConstraints($constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return parent::execute($image);
|
return parent::execute($image);
|
||||||
|
@@ -13,11 +13,14 @@ class HeightenCommand extends ResizeCommand
|
|||||||
public function execute($image)
|
public function execute($image)
|
||||||
{
|
{
|
||||||
$height = $this->argument(0)->type('digit')->required()->value();
|
$height = $this->argument(0)->type('digit')->required()->value();
|
||||||
|
$additionalConstraints = $this->argument(1)->type('closure')->value();
|
||||||
|
|
||||||
$this->arguments[0] = null;
|
$this->arguments[0] = null;
|
||||||
$this->arguments[1] = $height;
|
$this->arguments[1] = $height;
|
||||||
$this->arguments[2] = function ($constraint) {
|
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
|
if(is_callable($additionalConstraints))
|
||||||
|
$additionalConstraints($constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return parent::execute($image);
|
return parent::execute($image);
|
||||||
|
@@ -13,11 +13,14 @@ class WidenCommand extends ResizeCommand
|
|||||||
public function execute($image)
|
public function execute($image)
|
||||||
{
|
{
|
||||||
$width = $this->argument(0)->type('digit')->required()->value();
|
$width = $this->argument(0)->type('digit')->required()->value();
|
||||||
|
$additionalConstraints = $this->argument(1)->type('closure')->value();
|
||||||
|
|
||||||
$this->arguments[0] = $width;
|
$this->arguments[0] = $width;
|
||||||
$this->arguments[1] = null;
|
$this->arguments[1] = null;
|
||||||
$this->arguments[2] = function ($constraint) {
|
$this->arguments[2] = function ($constraint) use ($additionalConstraints) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
|
if(is_callable($additionalConstraints))
|
||||||
|
$additionalConstraints($constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return parent::execute($image);
|
return parent::execute($image);
|
||||||
|
@@ -195,6 +195,19 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertTransparentPosition($img, 60, 0);
|
$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()
|
public function testHeightenImage()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/tile.png');
|
$img = $this->manager()->make('tests/images/tile.png');
|
||||||
@@ -208,6 +221,19 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertTransparentPosition($img, 60, 0);
|
$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()
|
public function testResizeCanvasCenter()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/tile.png');
|
$img = $this->manager()->make('tests/images/tile.png');
|
||||||
|
@@ -197,6 +197,19 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertTransparentPosition($img, 60, 0);
|
$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()
|
public function testHeightenImage()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/tile.png');
|
$img = $this->manager()->make('tests/images/tile.png');
|
||||||
@@ -210,6 +223,19 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertTransparentPosition($img, 60, 0);
|
$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()
|
public function testResizeCanvasCenter()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/tile.png');
|
$img = $this->manager()->make('tests/images/tile.png');
|
||||||
|
Reference in New Issue
Block a user