diff options
author | Olivier Paroz <github@oparoz.com> | 2015-06-06 16:21:36 +0200 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-06-06 16:25:04 +0200 |
commit | 71d65cb713ebfb85ee19f9f3cd17dd915360fe9b (patch) | |
tree | 7281b8a32d148d27ae375dd1c45308416e63eee7 /lib/private/preview | |
parent | 16708ae1873ddd563c3177b87cf7a4c395dca609 (diff) | |
download | nextcloud-server-71d65cb713ebfb85ee19f9f3cd17dd915360fe9b.tar.gz nextcloud-server-71d65cb713ebfb85ee19f9f3cd17dd915360fe9b.zip |
Fix max preview, some resizing and caching issues and force preview providers to resize their previews properly
* introduces a method in OC_Image which doesn't stretch images when trying to make them fit in a box
* adds the method to all key providers so that they can do their job, as expected by the Preview class
* improves the caching mechanism of Preview in order to reduce I/O and to avoid filling the available disk space
* fixes some long standing issues
* **contains mostly tests**
Diffstat (limited to 'lib/private/preview')
-rw-r--r-- | lib/private/preview/image.php | 10 | ||||
-rw-r--r-- | lib/private/preview/movie.php | 7 | ||||
-rw-r--r-- | lib/private/preview/mp3.php | 7 | ||||
-rw-r--r-- | lib/private/preview/office.php | 24 | ||||
-rw-r--r-- | lib/private/preview/provider.php | 4 | ||||
-rw-r--r-- | lib/private/preview/svg.php | 13 |
6 files changed, 44 insertions, 21 deletions
diff --git a/lib/private/preview/image.php b/lib/private/preview/image.php index 2c69d29f4cb..dbaf5deb08d 100644 --- a/lib/private/preview/image.php +++ b/lib/private/preview/image.php @@ -33,7 +33,7 @@ abstract class Image extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { //get fileinfo $fileInfo = $fileview->getFileInfo($path); - if(!$fileInfo) { + if (!$fileInfo) { return false; } @@ -46,15 +46,19 @@ abstract class Image extends Provider { $image = new \OC_Image(); - if($fileInfo['encrypted'] === true) { + if ($fileInfo['encrypted'] === true) { $fileName = $fileview->toTmpFile($path); } else { $fileName = $fileview->getLocalFile($path); } $image->loadFromFile($fileName); $image->fixOrientation(); + if ($image->valid()) { + $image->scaleDownToFit($maxX, $maxY); - return $image->valid() ? $image : false; + return $image; + } + return false; } } diff --git a/lib/private/preview/movie.php b/lib/private/preview/movie.php index 1773f916a88..43e49bfb747 100644 --- a/lib/private/preview/movie.php +++ b/lib/private/preview/movie.php @@ -91,7 +91,6 @@ class Movie extends Provider { $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . - ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1'; } @@ -102,7 +101,11 @@ class Movie extends Provider { $image = new \OC_Image(); $image->loadFromFile($tmpPath); unlink($tmpPath); - return $image->valid() ? $image : false; + if ($image->valid()) { + $image->scaleDownToFit($maxX, $maxY); + + return $image; + } } unlink($tmpPath); return false; diff --git a/lib/private/preview/mp3.php b/lib/private/preview/mp3.php index ebeb5b989ce..49667d0dd05 100644 --- a/lib/private/preview/mp3.php +++ b/lib/private/preview/mp3.php @@ -47,7 +47,12 @@ class MP3 extends Provider { unlink($tmpPath); $image = new \OC_Image(); $image->loadFromData($picture); - return $image->valid() ? $image : $this->getNoCoverThumbnail(); + + if ($image->valid()) { + $image->scaleDownToFit($maxX, $maxY); + + return $image; + } } return $this->getNoCoverThumbnail(); diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index 54c0c26c079..0a61a32df40 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -29,7 +29,7 @@ abstract class Office extends Provider { */ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $this->initCmd(); - if(is_null($this->cmd)) { + if (is_null($this->cmd)) { return false; } @@ -37,7 +37,7 @@ abstract class Office extends Provider { $tmpDir = get_temp_dir(); - $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId().'/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir '; + $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir '; $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters); $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); @@ -46,8 +46,8 @@ abstract class Office extends Provider { //create imagick object from pdf $pdfPreview = null; - try{ - list( $dirname, , , $filename ) = array_values( pathinfo($absPath) ); + try { + list($dirname, , , $filename) = array_values(pathinfo($absPath)); $pdfPreview = $dirname . '/' . $filename . '.pdf'; $pdf = new \imagick($pdfPreview . '[0]'); @@ -65,27 +65,33 @@ abstract class Office extends Provider { unlink($absPath); unlink($pdfPreview); - return $image->valid() ? $image : false; + if ($image->valid()) { + $image->scaleDownToFit($maxX, $maxY); + + return $image; + } + return false; + } private function initCmd() { $cmd = ''; - if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + if (is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { $cmd = \OC_Config::getValue('preview_libreoffice_path', null); } $whichLibreOffice = shell_exec('command -v libreoffice'); - if($cmd === '' && !empty($whichLibreOffice)) { + if ($cmd === '' && !empty($whichLibreOffice)) { $cmd = 'libreoffice'; } $whichOpenOffice = shell_exec('command -v openoffice'); - if($cmd === '' && !empty($whichOpenOffice)) { + if ($cmd === '' && !empty($whichOpenOffice)) { $cmd = 'openoffice'; } - if($cmd === '') { + if ($cmd === '') { $cmd = null; } diff --git a/lib/private/preview/provider.php b/lib/private/preview/provider.php index ade91b8e232..ed1f3a1c5c9 100644 --- a/lib/private/preview/provider.php +++ b/lib/private/preview/provider.php @@ -1,7 +1,6 @@ <?php /** * @author Georg Ehrke <georg@owncloud.com> - * @author Georg Ehrke <georg@ownCloud.com> * @author Joas Schilling <nickvergessen@owncloud.com> * @author Jörn Friedrich Dreyer <jfd@butonic.de> * @author Robin Appelman <icewind@owncloud.com> @@ -54,7 +53,8 @@ abstract class Provider implements IProvider { } /** - * get thumbnail for file at path $path + * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, 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 diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php index 7c74fb6fde2..92d21c07385 100644 --- a/lib/private/preview/svg.php +++ b/lib/private/preview/svg.php @@ -35,17 +35,17 @@ class SVG extends Provider { * {@inheritDoc} */ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - try{ + try { $svg = new \Imagick(); $svg->setBackgroundColor(new \ImagickPixel('transparent')); $content = stream_get_contents($fileview->fopen($path, 'r')); - if(substr($content, 0, 5) !== '<?xml') { + if (substr($content, 0, 5) !== '<?xml') { $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content; } // Do not parse SVG files with references - if(stripos($content, 'xlink:href') !== false) { + if (stripos($content, 'xlink:href') !== false) { return false; } @@ -60,6 +60,11 @@ class SVG extends Provider { $image = new \OC_Image(); $image->loadFromData($svg); //check if image object is valid - return $image->valid() ? $image : false; + if ($image->valid()) { + $image->scaleDownToFit($maxX, $maxY); + + return $image; + } + return false; } } |