diff options
author | Frank Karlitschek <frank@owncloud.org> | 2013-10-17 01:48:34 -0700 |
---|---|---|
committer | Frank Karlitschek <frank@owncloud.org> | 2013-10-17 01:48:34 -0700 |
commit | 186c6a56d13206f03bbc80ecac59ff8c6df63840 (patch) | |
tree | 8f4bfe2079122ffa378403dc6938377b84d7424c /lib/private/preview | |
parent | d70a6c3f984be62ebbd2e8b5385de3d11a9aef06 (diff) | |
parent | 19ea4f79da63f640678c7eae0511f342ea2474b5 (diff) | |
download | nextcloud-server-186c6a56d13206f03bbc80ecac59ff8c6df63840.tar.gz nextcloud-server-186c6a56d13206f03bbc80ecac59ff8c6df63840.zip |
Merge pull request #4949 from owncloud/improve_unknown_preview_backend
use svg to generate filetype icon if imagick available
Diffstat (limited to 'lib/private/preview')
-rw-r--r-- | lib/private/preview/provider.php | 12 | ||||
-rw-r--r-- | lib/private/preview/unknown.php | 26 |
2 files changed, 33 insertions, 5 deletions
diff --git a/lib/private/preview/provider.php b/lib/private/preview/provider.php index e4a730bafc8..65d09705f40 100644 --- a/lib/private/preview/provider.php +++ b/lib/private/preview/provider.php @@ -11,9 +11,15 @@ abstract class Provider { abstract public function getMimeType(); /** - * search for $query - * @param string $query - * @return + * get thumbnail for file at path $path + * @param string $path Path of file + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image + * @param bool $scalingUp Disable/Enable upscaling of previews + * @param object $fileview fileview object of user folder + * @return mixed + * false if no preview was generated + * OC_Image object of the preview */ abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); } diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php index 9e6cd68d401..4747f9e25ed 100644 --- a/lib/private/preview/unknown.php +++ b/lib/private/preview/unknown.php @@ -20,8 +20,30 @@ class Unknown extends Provider { $path = \OC_Helper::mimetypeIcon($mimetype); $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT)); - return new \OC_Image($path); + $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'); + + $image = new \OC_Image(); + $image->loadFromData($svg); + } else { + $image = new \OC_Image($path); + } + + return $image; } } -\OC\Preview::registerProvider('OC\Preview\Unknown');
\ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\Unknown'); |