diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index f32d11fb..3918f77e 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -72,7 +72,7 @@ class Image /** * Attributes of the original created image * - * @var Array + * @var resource */ protected $original; @@ -1890,6 +1890,17 @@ class Image return $this->encoded; } + /** + * Destroys image resource and frees memory + * + * @return void + */ + public function destroy() + { + is_resource($this->resource) ? imagedestroy($this->resource) : null; + is_resource($this->original) ? imagedestroy($this->original) : null; + } + /** * Returns image stream * diff --git a/tests/ImageTest.php b/tests/ImageTest.php index d7ab1477..8f92ad24 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -1784,4 +1784,11 @@ class ImageTest extends PHPUnit_Framework_Testcase $img->encode(); $this->assertEquals($img->encoded, $img->encode()); } + + public function testDestroy() + { + $img = $this->getTestImage(); + $img->destroy(); + $this->assertEquals(get_resource_type($img->resource), 'Unknown'); + } }