1
0

IPreview.php 3.8 KB

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