summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-03-20 16:34:22 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-03-20 16:34:22 +0100
commitafa88729558b8dd26413ff49ada8678b1b6521c6 (patch)
tree86e6c662bef91e633816f2d72dac5115770c92ec /lib/public
parenta45e45df1ec357f9b390463ed74100e6c8b07fe7 (diff)
parent8f06353882877c948e15e0340615cc7d25c44b83 (diff)
downloadnextcloud-server-afa88729558b8dd26413ff49ada8678b1b6521c6.tar.gz
nextcloud-server-afa88729558b8dd26413ff49ada8678b1b6521c6.zip
Merge pull request #14857 from owncloud/preview-provider-registration-in-manager
Preview provider registration in manager
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/iavatar.php4
-rw-r--r--lib/public/iimage.php146
-rw-r--r--lib/public/ipreview.php34
-rw-r--r--lib/public/preview/iprovider.php39
4 files changed, 215 insertions, 8 deletions
diff --git a/lib/public/iavatar.php b/lib/public/iavatar.php
index 8f432c23fb8..984fe1075b4 100644
--- a/lib/public/iavatar.php
+++ b/lib/public/iavatar.php
@@ -16,7 +16,7 @@ interface IAvatar {
/**
* get the users avatar
* @param int $size size in px of the avatar, avatars are square, defaults to 64
- * @return boolean|\OC_Image containing the avatar or false if there's no image
+ * @return boolean|\OCP\IImage containing the avatar or false if there's no image
*/
function get($size = 64);
@@ -29,7 +29,7 @@ interface IAvatar {
/**
* sets the users avatar
- * @param \OC_Image|resource|string $data OC_Image, imagedata or path to set a new avatar
+ * @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar
* @throws \Exception if the provided file is not a jpg or png image
* @throws \Exception if the provided image is not valid
* @throws \OC\NotSquareException if the image is not square
diff --git a/lib/public/iimage.php b/lib/public/iimage.php
new file mode 100644
index 00000000000..01d8e101330
--- /dev/null
+++ b/lib/public/iimage.php
@@ -0,0 +1,146 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Joas Schilling
+ * @copyright 2015 Joas Schilling nickvergessen@owncloud.com
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP;
+
+/**
+ * Class for basic image manipulation
+ */
+interface IImage {
+ /**
+ * Determine whether the object contains an image resource.
+ *
+ * @return bool
+ */
+ public function valid();
+
+ /**
+ * Returns the MIME type of the image or an empty string if no image is loaded.
+ *
+ * @return string
+ */
+ public function mimeType();
+
+ /**
+ * Returns the width of the image or -1 if no image is loaded.
+ *
+ * @return int
+ */
+ public function width();
+
+ /**
+ * Returns the height of the image or -1 if no image is loaded.
+ *
+ * @return int
+ */
+ public function height();
+
+ /**
+ * Returns the width when the image orientation is top-left.
+ *
+ * @return int
+ */
+ public function widthTopLeft();
+
+ /**
+ * Returns the height when the image orientation is top-left.
+ *
+ * @return int
+ */
+ public function heightTopLeft();
+
+ /**
+ * Outputs the image.
+ *
+ * @param string $mimeType
+ * @return bool
+ */
+ public function show($mimeType = null);
+
+ /**
+ * Saves the image.
+ *
+ * @param string $filePath
+ * @param string $mimeType
+ * @return bool
+ */
+ public function save($filePath = null, $mimeType = null);
+
+ /**
+ * @return resource Returns the image resource in any.
+ */
+ public function resource();
+
+ /**
+ * @return string Returns the raw image data.
+ */
+ public function data();
+
+ /**
+ * (I'm open for suggestions on better method name ;)
+ * Get the orientation based on EXIF data.
+ *
+ * @return int The orientation or -1 if no EXIF data is available.
+ */
+ public function getOrientation();
+
+ /**
+ * (I'm open for suggestions on better method name ;)
+ * Fixes orientation based on EXIF data.
+ *
+ * @return bool.
+ */
+ public function fixOrientation();
+
+ /**
+ * Resizes the image preserving ratio.
+ *
+ * @param integer $maxSize The maximum size of either the width or height.
+ * @return bool
+ */
+ public function resize($maxSize);
+
+ /**
+ * @param int $width
+ * @param int $height
+ * @return bool
+ */
+ public function preciseResize($width, $height);
+
+ /**
+ * Crops the image to the middle square. If the image is already square it just returns.
+ *
+ * @param int $size maximum size for the result (optional)
+ * @return bool for success or failure
+ */
+ public function centerCrop($size = 0);
+
+ /**
+ * Crops the image from point $x$y with dimension $wx$h.
+ *
+ * @param int $x Horizontal position
+ * @param int $y Vertical position
+ * @param int $w Width
+ * @param int $h Height
+ * @return bool for success or failure
+ */
+ public function crop($x, $y, $w, $h);
+
+ /**
+ * Resizes the image to fit within a boundary while preserving ratio.
+ *
+ * @param integer $maxWidth
+ * @param integer $maxHeight
+ * @return bool
+ */
+ public function fitIn($maxWidth, $maxHeight);
+}
diff --git a/lib/public/ipreview.php b/lib/public/ipreview.php
index cc756ef80d3..202b0d03948 100644
--- a/lib/public/ipreview.php
+++ b/lib/public/ipreview.php
@@ -36,8 +36,30 @@ namespace OCP;
/**
* This class provides functions to render and show thumbnails and previews of files
*/
-interface IPreview
-{
+interface IPreview {
+ /**
+ * In order to improve lazy loading a closure can be registered which will be
+ * called in case preview providers are actually requested
+ *
+ * $callable has to return an instance of \OCP\Preview\IProvider
+ *
+ * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
+ * @param \Closure $callable
+ * @return void
+ */
+ public function registerProvider($mimeTypeRegex, \Closure $callable);
+
+ /**
+ * Get all providers
+ * @return array
+ */
+ public function getProviders();
+
+ /**
+ * Does the manager have any providers
+ * @return bool
+ */
+ public function hasProviders();
/**
* Return a preview of a file
@@ -45,9 +67,9 @@ interface IPreview
* @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 boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly
- * @return \OCP\Image
+ * @return \OCP\IImage
*/
- function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false);
+ public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false);
/**
@@ -55,7 +77,7 @@ interface IPreview
* @param string $mimeType
* @return boolean
*/
- function isMimeSupported($mimeType = '*');
+ public function isMimeSupported($mimeType = '*');
/**
* Check if a preview can be generated for a file
@@ -63,5 +85,5 @@ interface IPreview
* @param \OCP\Files\FileInfo $file
* @return bool
*/
- function isAvailable($file);
+ public function isAvailable(\OCP\Files\FileInfo $file);
}
diff --git a/lib/public/preview/iprovider.php b/lib/public/preview/iprovider.php
new file mode 100644
index 00000000000..4318ecd37ac
--- /dev/null
+++ b/lib/public/preview/iprovider.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Joas Schilling
+ * @copyright 2015 Joas Schilling nickvergessen@owncloud.com
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OCP\Preview;
+
+interface IProvider {
+ /**
+ * @return string Regex with the mimetypes that are supported by this provider
+ */
+ public function getMimeType();
+
+ /**
+ * Check if a preview can be generated for $path
+ *
+ * @param \OCP\Files\FileInfo $file
+ * @return bool
+ */
+ public function isAvailable(\OCP\Files\FileInfo $file);
+
+ /**
+ * 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 \OC\Files\View $fileview fileview object of user folder
+ * @return bool|\OCP\IImage false if no preview was generated
+ */
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview);
+}