From 6fd584686f94fbf729e78ce4be309da1d0e092fa Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 20 Feb 2014 16:56:17 +0100 Subject: [PATCH] rewritten cloneResource method --- src/Intervention/Image/Image.php | 7 ++++--- tests/ImageTest.php | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 9b7cd8bd..f32d11fb 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -1758,9 +1758,10 @@ class Image */ private function cloneResource($resource) { - ob_start(); - imagegd2($resource); - return imagecreatefromstring(ob_get_clean()); + $clone = imagecreatetruecolor($this->width, $this->height); + imagecopy($clone, $resource, 0, 0, 0, 0, $this->width, $this->height); + + return $clone; } /** diff --git a/tests/ImageTest.php b/tests/ImageTest.php index aaab3d72..d7ab1477 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -1354,12 +1354,25 @@ class ImageTest extends PHPUnit_Framework_Testcase $img = new Image(null, 800, 600, '#0000ff'); $img->fill('#00ff00'); $img->backup(); + $img->resize(200, 200); $img->reset(); $this->assertInternalType('int', $img->width); $this->assertInternalType('int', $img->height); $this->assertEquals($img->width, 800); $this->assertEquals($img->height, 600); $this->assertEquals('#00ff00', $img->pickColor(0, 0, 'hex')); + + $img = new Image('public/tile.png'); + $img->resize(10, 10); + $img->fill('#00ff00'); + $img->backup(); + $img->resize(5, 5); + $img->reset(); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 10); + $this->assertEquals($img->height, 10); + $this->assertEquals('#00ff00', $img->pickColor(0, 0, 'hex')); } public function testLimitColors()