]> source.dussan.org Git - nextcloud-server.git/commitdiff
Preserve transparency when loading from a file
authorkondou <kondou@ts.unde.re>
Tue, 12 Aug 2014 09:00:00 +0000 (11:00 +0200)
committerkondou <kondou@ts.unde.re>
Wed, 10 Sep 2014 21:49:21 +0000 (23:49 +0200)
Fix #7148 - again :)

lib/private/image.php
tests/lib/image.php

index 7ddc8dca1433cc9ea412ff97015a4d2f5d39b7ca..bab91745c0505593cb8b2597bfbc680085a5f38c 100644 (file)
@@ -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,
index 131a9d86f3eaef89200d003bdbff303581cd1eb1..795bc4641595be562a04f4768c2e9a19e9c688e2 100644 (file)
@@ -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();