1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-18 19:51:22 +02:00

added option to reset an "empty" image

This commit is contained in:
Oliver Vogel
2013-02-25 20:51:16 +01:00
parent 93d3362265
commit aa4f78b92f
2 changed files with 30 additions and 2 deletions

View File

@@ -70,6 +70,13 @@ class Image
*/
protected $filesystem;
/**
* Attributes of the original created image
*
* @var Array
*/
protected $original;
/**
* Create a new instance of Image class
*
@@ -152,6 +159,9 @@ class Image
$this->width = is_numeric($width) ? intval($width) : 1;
$this->height = is_numeric($height) ? intval($height) : 1;
$this->original['width'] = $this->width;
$this->original['height'] = $this->height;
// create empty image
$this->resource = @imagecreatetruecolor($this->width, $this->height);
@@ -593,7 +603,14 @@ class Image
*/
public function reset()
{
if (is_null($this->dirname) && is_null($this->basename)) {
$this->setProperties(null, $this->original['width'], $this->original['height']);
} else {
$this->setProperties($this->dirname .'/'. $this->basename);
}
return $this;
}

View File

@@ -290,6 +290,17 @@ class ImageTest extends PHPUnit_Framework_Testcase
$this->assertEquals($img->height, 600);
}
public function testResetEmptyImage()
{
$img = new Image(null, 800, 600);
$img->resize(300, 200);
$img->reset();
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 800);
$this->assertEquals($img->height, 600);
}
public function testSaveImage()
{
$save_as = 'public/test2.jpg';