Merge pull request #4949 from owncloud/improve_unknown_preview_backend

use svg to generate filetype icon if imagick available
This commit is contained in:
Frank Karlitschek 2013-10-17 01:48:34 -07:00
commit 186c6a56d1
2 changed files with 33 additions and 5 deletions

View File

@ -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);
}

View File

@ -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');
\OC\Preview::registerProvider('OC\Preview\Unknown');