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

added legacy resizing method

This commit is contained in:
Oliver Vogel
2013-02-24 20:03:14 +01:00
parent c561fb9f2e
commit f93b3b571c
3 changed files with 39 additions and 5 deletions

View File

@@ -21,22 +21,18 @@ Open your Laravel config file `config/app.php` and add the following lines.
In the `$providers` array add the service providers for this package.
'providers' => array(
...
'Intervention\Image\ImageServiceProvider'
),
Add the facade of this package to the `$aliases` array.
'aliases' => array(
...
'Image' => 'Intervention\Image\Facades\Image'
),
## Usage
@@ -85,7 +81,7 @@ $img->resize(300, null, true);
// resize the image to a height of 200 and constrain aspect ratio (auto width)
$img->resize(null, 200, true);
// prevent upsizing with optional fourth parameter
// prevent possible upsizing with optional fourth parameter
$img->resize(null, 400, true, false);
// Reset image resource to original

View File

@@ -200,6 +200,12 @@ class Image
*/
public function resize($width = null, $height = null, $ratio = false, $upsize = true)
{
// catch legacy call
if (is_array($width)) {
$dimensions = $width;
return $this->legacyResize($dimensions);
}
// Evaluate passed parameters.
$width = isset($width) ? intval($width) : null;
$height = $max_height = isset($height) ? intval($height) : null;
@@ -275,6 +281,19 @@ class Image
return $this->modify(0, 0, 0, 0, $width, $height, $this->width, $this->height);
}
/**
* Legacy method to support old resizing calls
*
* @param array $dimensions
* @return Image
*/
public function legacyResize($dimensions = array())
{
$width = array_key_exists('width', $dimensions) ? intval($dimensions['width']) : null;
$height = array_key_exists('height', $dimensions) ? intval($dimensions['height']) : null;
return $this->resize($width, $height, true);
}
/**
* Cut out a detail of the image in given ratio and resize to output size
*

View File

@@ -107,6 +107,25 @@ class ImageTest extends PHPUnit_Framework_Testcase
$this->assertEquals($img->height, $original_height);
}
public function testLegacyResize()
{
// auto height
$img = $this->getTestImage();
$img->resize(array('width' => '320'));
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 320);
$this->assertEquals($img->height, 240);
// auto width
$img = $this->getTestImage();
$img->resize(array('height' => '240'));
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 320);
$this->assertEquals($img->height, 240);
}
public function testGrabImage()
{
$img = $this->getTestImage();