[Pkg-owncloud-commits] [owncloud] 26/205: Move media type icon preview creation to its own method
David Prévot
taffit at moszumanska.debian.org
Thu Jul 2 17:36:51 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch stable8
in repository owncloud.
commit 8193e1d7c15485663eeaaa1af1480f1f19004c32
Author: Olivier Paroz <github at oparoz.com>
Date: Thu Jun 18 13:24:15 2015 +0200
Move media type icon preview creation to its own method
---
lib/private/preview.php | 29 +++++++++++++++++++++++++----
tests/lib/preview.php | 21 +++++++++++++++++++++
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/lib/private/preview.php b/lib/private/preview.php
index d8a9a3e..3a34150 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;
@@ -1095,6 +1092,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
*
* @param string $previewPath path to the preview
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index 2741018..70b7218 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -210,6 +210,27 @@ class Preview extends TestCase {
}
/**
+ * Tests if the media type icon fits into the asked dimensions
+ */
+ public function testIsMimePreviewTheRightSize() {
+ $width = 400;
+ $height = 200;
+
+ // Previews for odt files are not enabled
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.odt');
+ $imgPath = '/' . self::TEST_PREVIEW_USER1 . '/files/testimage.odt';
+ $this->rootView->file_put_contents($imgPath, $imgData);
+
+ $preview =
+ new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.odt', $width, $height);
+ $preview->getPreview();
+ $image = $preview->getPreview();
+
+ $this->assertSame($width, $image->width());
+ $this->assertSame($height, $image->height());
+ }
+
+ /**
* We generate the data to use as it makes it easier to adjust in case we need to test
* something different
*
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list