IPreview.php 3.6 KB

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