From 8193e1d7c15485663eeaaa1af1480f1f19004c32 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Thu, 18 Jun 2015 13:24:15 +0200 Subject: Move media type icon preview creation to its own method --- lib/private/preview.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'lib/private/preview.php') diff --git a/lib/private/preview.php b/lib/private/preview.php index d8a9a3e1b78..3a341500e67 100644 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -703,10 +703,7 @@ class Preview { // We still don't have a preview, so we send back the mime icon if (is_null($this->preview)) { - $this->preview = new \OC_Image(); - $mimeIconWebPath = \OC_Helper::mimetypeIcon($this->mimeType); - $mimeIconServerPath = str_replace(\OC::$WEBROOT, \OC::$SERVERROOT, $mimeIconWebPath); - $this->preview->loadFromFile($mimeIconServerPath); + $this->getMimeIcon(); } return $this->preview; @@ -1094,6 +1091,30 @@ class Preview { } } + /** + * Creates a mime icon preview of the asked dimensions + * + * This will paste the mime icon in the middle of an empty preview of the asked dimension + */ + private function getMimeIcon() { + $image = new \OC_Image(); + $mimeIconWebPath = \OC_Helper::mimetypeIcon($this->mimeType); + if (empty(\OC::$WEBROOT)) { + $mimeIconServerPath = \OC::$SERVERROOT . $mimeIconWebPath; + } else { + $mimeIconServerPath = str_replace(\OC::$WEBROOT, \OC::$SERVERROOT, $mimeIconWebPath); + } + $image->loadFromFile($mimeIconServerPath); + + $previewWidth = (int)$image->width(); + $previewHeight = (int)$image->height(); + $askedWidth = $this->getMaxX(); + $askedHeight = $this->getMaxY(); + $this->cropAndFill( + $image, $askedWidth, $askedHeight, $previewWidth, $previewHeight + ); + } + /** * Stores the max preview in the cache * -- cgit v1.2.3