]> source.dussan.org Git - nextcloud-server.git/commitdiff
resize svg without loosing quality
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 10 Oct 2013 22:12:37 +0000 (00:12 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 10 Oct 2013 22:12:37 +0000 (00:12 +0200)
lib/private/preview/unknown.php

index 62444ac6a24593f77e13b05eb08da3d199842b51..4747f9e25ed0633010d08eac3ea1d4249af515a0 100644 (file)
@@ -23,7 +23,15 @@ class Unknown extends Provider {
                $svgPath = substr_replace($path, 'svg', -3);
 
                if (extension_loaded('imagick') && file_exists($svgPath)) {
+
+                       // http://www.php.net/manual/de/imagick.setresolution.php#85284
                        $svg = new \Imagick();
+                       $svg->readImage($svgPath);
+                       $res = $svg->getImageResolution();
+                       $x_ratio = $res['x'] / $svg->getImageWidth();
+                       $y_ratio = $res['y'] / $svg->getImageHeight();
+                       $svg->removeImage();
+                       $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
                        $svg->setBackgroundColor(new \ImagickPixel('transparent'));
                        $svg->readImage($svgPath);
                        $svg->setImageFormat('png32');