From aa4f78b92f5348c4cb38fdaaba47268db3af9819 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Mon, 25 Feb 2013 20:51:16 +0100 Subject: [PATCH] added option to reset an "empty" image --- src/Intervention/Image/Image.php | 21 +++++++++++++++++++-- tests/ImageTest.php | 11 +++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 8e2e40f8..921ef551 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -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() { - $this->setProperties($this->dirname .'/'. $this->basename); + 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; } @@ -742,7 +759,7 @@ class Image { $path = is_null($path) ? ($this->dirname .'/'. $this->basename) : $path; file_put_contents($path, $this->data($this->filesystem->extension($path), $quality)); - + return $this; } diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 0f0a9b79..055e12f4 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -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';