From: kondou Date: Tue, 12 Aug 2014 09:00:00 +0000 (+0200) Subject: Preserve transparency when loading from a file X-Git-Tag: v8.0.0alpha1~693^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=18ef7bf1edbb2046e473765cbc25eae3299590e9;p=nextcloud-server.git Preserve transparency when loading from a file Fix #7148 - again :) --- diff --git a/lib/private/image.php b/lib/private/image.php index 7ddc8dca143..bab91745c05 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -450,6 +450,9 @@ class OC_Image { case IMAGETYPE_GIF: if (imagetypes() & IMG_GIF) { $this->resource = imagecreatefromgif($imagePath); + // Preserve transparency + imagealphablending($this->resource, true); + imagesavealpha($this->resource, true); } else { OC_Log::write('core', 'OC_Image->loadFromFile, GIF images not supported: '.$imagePath, @@ -468,6 +471,9 @@ class OC_Image { case IMAGETYPE_PNG: if (imagetypes() & IMG_PNG) { $this->resource = imagecreatefrompng($imagePath); + // Preserve transparency + imagealphablending($this->resource, true); + imagesavealpha($this->resource, true); } else { OC_Log::write('core', 'OC_Image->loadFromFile, PNG images not supported: '.$imagePath, diff --git a/tests/lib/image.php b/tests/lib/image.php index 131a9d86f3e..795bc464159 100644 --- a/tests/lib/image.php +++ b/tests/lib/image.php @@ -115,6 +115,9 @@ class Test_Image extends PHPUnit_Framework_TestCase { public function testData() { $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.png')); + // Preserve transparency + imagealphablending($raw, true); + imagesavealpha($raw, true); ob_start(); imagepng($raw); $expected = ob_get_clean();