Skip to content

Commit

Permalink
added legacy resizing method
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Feb 24, 2013
1 parent c561fb9 commit f93b3b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/Intervention/Image/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ private function modify($dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $s
*/
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;
Expand Down Expand Up @@ -275,6 +281,19 @@ public function resize($width = null, $height = null, $ratio = false, $upsize =
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
*
Expand Down
19 changes: 19 additions & 0 deletions tests/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ public function testResizeImage()
$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();
Expand Down

0 comments on commit f93b3b5

Please sign in to comment.