IPreview.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. /**
  27. * Public interface of ownCloud for apps to use.
  28. * Preview interface
  29. *
  30. */
  31. // use OCP namespace for all classes that are considered public.
  32. // This means that they should be used by apps instead of the internal ownCloud classes
  33. namespace OCP;
  34. use OCP\Files\File;
  35. use OCP\Files\SimpleFS\ISimpleFile;
  36. use OCP\Files\NotFoundException;
  37. /**
  38. * This class provides functions to render and show thumbnails and previews of files
  39. * @since 6.0.0
  40. */
  41. interface IPreview {
  42. /**
  43. * @since 9.2.0
  44. */
  45. const EVENT = self::class . ':' . 'PreviewRequested';
  46. const MODE_FILL = 'fill';
  47. const MODE_COVER = 'cover';
  48. /**
  49. * In order to improve lazy loading a closure can be registered which will be
  50. * called in case preview providers are actually requested
  51. *
  52. * $callable has to return an instance of \OCP\Preview\IProvider
  53. *
  54. * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
  55. * @param \Closure $callable
  56. * @return void
  57. * @since 8.1.0
  58. */
  59. public function registerProvider($mimeTypeRegex, \Closure $callable);
  60. /**
  61. * Get all providers
  62. * @return array
  63. * @since 8.1.0
  64. */
  65. public function getProviders();
  66. /**
  67. * Does the manager have any providers
  68. * @return bool
  69. * @since 8.1.0
  70. */
  71. public function hasProviders();
  72. /**
  73. * Return a preview of a file
  74. * @param string $file The path to the file where you want a thumbnail from
  75. * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
  76. * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
  77. * @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly
  78. * @return \OCP\IImage
  79. * @since 6.0.0
  80. * @deprecated 11 Use getPreview
  81. */
  82. public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false);
  83. /**
  84. * Returns a preview of a file
  85. *
  86. * The cache is searched first and if nothing usable was found then a preview is
  87. * generated by one of the providers
  88. *
  89. * @param File $file
  90. * @param int $width
  91. * @param int $height
  92. * @param bool $crop
  93. * @param string $mode
  94. * @param string $mimeType To force a given mimetype for the file (files_versions needs this)
  95. * @return ISimpleFile
  96. * @throws NotFoundException
  97. * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
  98. * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0
  99. */
  100. public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null);
  101. /**
  102. * Returns true if the passed mime type is supported
  103. * @param string $mimeType
  104. * @return boolean
  105. * @since 6.0.0
  106. */
  107. public function isMimeSupported($mimeType = '*');
  108. /**
  109. * Check if a preview can be generated for a file
  110. *
  111. * @param \OCP\Files\FileInfo $file
  112. * @return bool
  113. * @since 8.0.0
  114. */
  115. public function isAvailable(\OCP\Files\FileInfo $file);
  116. }