Merge pull request #10362 from owncloud/preserve_transparency_on_fileload

Preserve transparency when loading from a file
This commit is contained in:
Morris Jobke 2014-09-16 08:33:56 +02:00
commit 245a0e2ad8
2 changed files with 9 additions and 0 deletions

View 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,

View 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();