You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nextcloud-server/lib/private/preview/unknown.php

50 lines
1.4 KiB

<?php
/**
* Copyright (c) 2013 Frank Karlitschek frank@owncloud.org
12 years ago
* Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Preview;
12 years ago
class Unknown extends Provider {
public function getMimeType() {
return '/.*/';
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
$mimetype = $fileview->getMimeType($path);
$path = \OC_Helper::mimetypeIcon($mimetype);
$path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
$svgPath = substr_replace($path, 'svg', -3);
if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
// http://www.php.net/manual/de/imagick.setresolution.php#85284
12 years ago
$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);
12 years ago
$svg->setBackgroundColor(new \ImagickPixel('transparent'));
$svg->readImage($svgPath);
$svg->setImageFormat('png32');
12 years ago
$image = new \OC_Image();
$image->loadFromData($svg);
} else {
$image = new \OC_Image($path);
}
return $image;
12 years ago
}
}
12 years ago
\OC\Preview::registerProvider('OC\Preview\Unknown');