From 825d8610d0abbf1063df3019533253908142ae43 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 15 Aug 2013 13:21:35 +0200 Subject: [PATCH] fix svg and cache transparency issue --- lib/image.php | 3 +++ lib/preview.php | 2 ++ lib/preview/svg.php | 8 +++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/image.php b/lib/image.php index 4bc38e20e5..53ffb24d18 100644 --- a/lib/image.php +++ b/lib/image.php @@ -496,6 +496,9 @@ class OC_Image { return false; } $this->resource = @imagecreatefromstring($str); + imagealphablending($this->resource, false); + imagesavealpha($this->resource, true); + if(!$this->resource) { OC_Log::write('core', 'OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG); return false; diff --git a/lib/preview.php b/lib/preview.php index 293accb188..e7dd327d02 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -391,6 +391,8 @@ class Preview { continue; } + \OC_Log::write('core', 'Generating preview for "' . $file . '" with "' . get_class($provider) . '"', \OC_Log::DEBUG); + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileview); if(!($preview instanceof \OC_Image)) { diff --git a/lib/preview/svg.php b/lib/preview/svg.php index e939e526b1..b49e51720f 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -18,7 +18,7 @@ if (extension_loaded('imagick')) { public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { try{ $svg = new \Imagick(); - $svg->setResolution($maxX, $maxY); + $svg->setBackgroundColor(new \ImagickPixel('transparent')); $content = stream_get_contents($fileview->fopen($path, 'r')); if(substr($content, 0, 5) !== 'readImageBlob($content); - $svg->setImageFormat('jpg'); + $svg->setImageFormat('png32'); } catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } + //new image object - $image = new \OC_Image($svg); + $image = new \OC_Image(); + $image->loadFromData($svg); //check if image object is valid return $image->valid() ? $image : false; }