From f93b3b571cc103074f377c17b9937d9082048242 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 24 Feb 2013 20:03:14 +0100 Subject: [PATCH] added legacy resizing method --- README.md | 6 +----- src/Intervention/Image/Image.php | 19 +++++++++++++++++++ tests/ImageTest.php | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d711ce05..90dfa996 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 2f6afb14..eb46ca4e 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -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 * diff --git a/tests/ImageTest.php b/tests/ImageTest.php index aa088762..b9f16a20 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -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();