From: Jörn Friedrich Dreyer Date: Fri, 22 Feb 2013 11:42:40 +0000 (+0100) Subject: keep transparency when resizing or cropping png/gif X-Git-Tag: v5.0.0beta2~28^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=16a5f15f85cabfaa0c0fc66151e850119b64e64b;p=nextcloud-server.git keep transparency when resizing or cropping png/gif --- diff --git a/lib/image.php b/lib/image.php index 7b0cbefd657..dc1c6df85ae 100644 --- a/lib/image.php +++ b/lib/image.php @@ -702,6 +702,13 @@ class OC_Image { return false; } + // preserve transparency + if($this->imagetype == IMAGETYPE_GIF or $this->imagetype == IMAGETYPE_PNG) { + imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127)); + imagealphablending($process, false); + imagesavealpha($process, true); + } + imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); if ($process == false) { OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$width.'x'.$height, OC_Log::ERROR); @@ -751,6 +758,14 @@ class OC_Image { imagedestroy($process); return false; } + + // preserve transparency + if($this->imagetype == IMAGETYPE_GIF or $this->imagetype == IMAGETYPE_PNG) { + imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127)); + imagealphablending($process, false); + imagesavealpha($process, true); + } + imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height); if ($process == false) { OC_Log::write('core',