IPreview.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP;
  10. use OCP\Files\File;
  11. use OCP\Files\NotFoundException;
  12. use OCP\Files\SimpleFS\ISimpleFile;
  13. /**
  14. * This class provides functions to render and show thumbnails and previews of files
  15. * @since 6.0.0
  16. */
  17. interface IPreview {
  18. /**
  19. * @since 11.0.0
  20. */
  21. public const MODE_FILL = 'fill';
  22. /**
  23. * @since 11.0.0
  24. */
  25. public const MODE_COVER = 'cover';
  26. /**
  27. * In order to improve lazy loading a closure can be registered which will be
  28. * called in case preview providers are actually requested
  29. *
  30. * $callable has to return an instance of \OCP\Preview\IProvider
  31. *
  32. * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
  33. * @param \Closure $callable
  34. * @return void
  35. * @since 8.1.0
  36. * @see \OCP\AppFramework\Bootstrap\IRegistrationContext::registerPreviewProvider
  37. *
  38. * @deprecated 23.0.0 Register your provider via the IRegistrationContext when booting the app
  39. */
  40. public function registerProvider($mimeTypeRegex, \Closure $callable);
  41. /**
  42. * Get all providers
  43. * @return array
  44. * @since 8.1.0
  45. */
  46. public function getProviders();
  47. /**
  48. * Does the manager have any providers
  49. * @return bool
  50. * @since 8.1.0
  51. */
  52. public function hasProviders();
  53. /**
  54. * Returns a preview of a file
  55. *
  56. * The cache is searched first and if nothing usable was found then a preview is
  57. * generated by one of the providers
  58. *
  59. * @param File $file
  60. * @param int $width
  61. * @param int $height
  62. * @param bool $crop
  63. * @param string $mode
  64. * @param string $mimeType To force a given mimetype for the file (files_versions needs this)
  65. * @return ISimpleFile
  66. * @throws NotFoundException
  67. * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
  68. * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0
  69. */
  70. public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null);
  71. /**
  72. * Returns true if the passed mime type is supported
  73. * @param string $mimeType
  74. * @return boolean
  75. * @since 6.0.0
  76. */
  77. public function isMimeSupported($mimeType = '*');
  78. /**
  79. * Check if a preview can be generated for a file
  80. *
  81. * @param \OCP\Files\FileInfo $file
  82. * @return bool
  83. * @since 8.0.0
  84. */
  85. public function isAvailable(\OCP\Files\FileInfo $file);
  86. /**
  87. * Generates previews of a file
  88. *
  89. * @param File $file
  90. * @param array $specifications
  91. * @param string $mimeType
  92. * @return ISimpleFile the last preview that was generated
  93. * @throws NotFoundException
  94. * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
  95. * @since 19.0.0
  96. */
  97. public function generatePreviews(File $file, array $specifications, $mimeType = null);
  98. }