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:
@@ -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.
|
In the `$providers` array add the service providers for this package.
|
||||||
|
|
||||||
'providers' => array(
|
'providers' => array(
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
'Intervention\Image\ImageServiceProvider'
|
'Intervention\Image\ImageServiceProvider'
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
||||||
Add the facade of this package to the `$aliases` array.
|
Add the facade of this package to the `$aliases` array.
|
||||||
|
|
||||||
'aliases' => array(
|
'aliases' => array(
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
'Image' => 'Intervention\Image\Facades\Image'
|
'Image' => 'Intervention\Image\Facades\Image'
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -85,7 +81,7 @@ $img->resize(300, null, true);
|
|||||||
// resize the image to a height of 200 and constrain aspect ratio (auto width)
|
// resize the image to a height of 200 and constrain aspect ratio (auto width)
|
||||||
$img->resize(null, 200, true);
|
$img->resize(null, 200, true);
|
||||||
|
|
||||||
// prevent upsizing with optional fourth parameter
|
// prevent possible upsizing with optional fourth parameter
|
||||||
$img->resize(null, 400, true, false);
|
$img->resize(null, 400, true, false);
|
||||||
|
|
||||||
// Reset image resource to original
|
// Reset image resource to original
|
||||||
|
@@ -200,6 +200,12 @@ class Image
|
|||||||
*/
|
*/
|
||||||
public function resize($width = null, $height = null, $ratio = false, $upsize = true)
|
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.
|
// Evaluate passed parameters.
|
||||||
$width = isset($width) ? intval($width) : null;
|
$width = isset($width) ? intval($width) : null;
|
||||||
$height = $max_height = isset($height) ? intval($height) : 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);
|
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
|
* Cut out a detail of the image in given ratio and resize to output size
|
||||||
*
|
*
|
||||||
|
@@ -107,6 +107,25 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
$this->assertEquals($img->height, $original_height);
|
$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()
|
public function testGrabImage()
|
||||||
{
|
{
|
||||||
$img = $this->getTestImage();
|
$img = $this->getTestImage();
|
||||||
|
Reference in New Issue
Block a user