ImageStyleInterface.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace Drupal\image;
  3. use Drupal\Core\Config\Entity\ConfigEntityInterface;
  4. /**
  5. * Provides an interface defining an image style entity.
  6. */
  7. interface ImageStyleInterface extends ConfigEntityInterface {
  8. /**
  9. * Returns the replacement ID.
  10. *
  11. * @return string|null
  12. * The replacement image style ID or NULL if no replacement has been
  13. * selected.
  14. *
  15. * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.x. Use
  16. * \Drupal\image\ImageStyleStorageInterface::getReplacementId() instead.
  17. *
  18. * @see \Drupal\image\ImageStyleStorageInterface::getReplacementId()
  19. */
  20. public function getReplacementID();
  21. /**
  22. * Returns the image style.
  23. *
  24. * @return string
  25. * The name of the image style.
  26. */
  27. public function getName();
  28. /**
  29. * Sets the name of the image style.
  30. *
  31. * @param string $name
  32. * The name of the image style.
  33. *
  34. * @return \Drupal\image\ImageStyleInterface
  35. * The class instance this method is called on.
  36. */
  37. public function setName($name);
  38. /**
  39. * Returns the URI of this image when using this style.
  40. *
  41. * The path returned by this function may not exist. The default generation
  42. * method only creates images when they are requested by a user's browser.
  43. * Modules may implement this method to decide where to place derivatives.
  44. *
  45. * @param string $uri
  46. * The URI or path to the original image.
  47. *
  48. * @return string
  49. * The URI to the image derivative for this style.
  50. */
  51. public function buildUri($uri);
  52. /**
  53. * Returns the URL of this image derivative for an original image path or URI.
  54. *
  55. * @param string $path
  56. * The path or URI to the original image.
  57. * @param mixed $clean_urls
  58. * (optional) Whether clean URLs are in use.
  59. *
  60. * @return string
  61. * The absolute URL where a style image can be downloaded, suitable for use
  62. * in an <img> tag. Requesting the URL will cause the image to be created.
  63. *
  64. * @see \Drupal\image\Controller\ImageStyleDownloadController::deliver()
  65. * @see file_url_transform_relative()
  66. */
  67. public function buildUrl($path, $clean_urls = NULL);
  68. /**
  69. * Generates a token to protect an image style derivative.
  70. *
  71. * This prevents unauthorized generation of an image style derivative,
  72. * which can be costly both in CPU time and disk space.
  73. *
  74. * @param string $uri
  75. * The URI of the original image of this style.
  76. *
  77. * @return string
  78. * An eight-character token which can be used to protect image style
  79. * derivatives against denial-of-service attacks.
  80. */
  81. public function getPathToken($uri);
  82. /**
  83. * Flushes cached media for this style.
  84. *
  85. * @param string $path
  86. * (optional) The original image path or URI. If it's supplied, only this
  87. * image derivative will be flushed.
  88. *
  89. * @return $this
  90. */
  91. public function flush($path = NULL);
  92. /**
  93. * Creates a new image derivative based on this image style.
  94. *
  95. * Generates an image derivative applying all image effects and saving the
  96. * resulting image.
  97. *
  98. * @param string $original_uri
  99. * Original image file URI.
  100. * @param string $derivative_uri
  101. * Derivative image file URI.
  102. *
  103. * @return bool
  104. * TRUE if an image derivative was generated, or FALSE if the image
  105. * derivative could not be generated.
  106. */
  107. public function createDerivative($original_uri, $derivative_uri);
  108. /**
  109. * Determines the dimensions of this image style.
  110. *
  111. * Stores the dimensions of this image style into $dimensions associative
  112. * array. Implementations have to provide at least values to next keys:
  113. * - width: Integer with the derivative image width.
  114. * - height: Integer with the derivative image height.
  115. *
  116. * @param array $dimensions
  117. * Associative array passed by reference. Implementations have to store the
  118. * resulting width and height, in pixels.
  119. * @param string $uri
  120. * Original image file URI. It is passed in to allow effects to
  121. * optionally use this information to retrieve additional image metadata
  122. * to determine dimensions of the styled image.
  123. * ImageStyleInterface::transformDimensions key objective is to calculate
  124. * styled image dimensions without performing actual image operations, so
  125. * be aware that performing IO on the URI may lead to decrease in
  126. * performance.
  127. *
  128. * @see ImageEffectInterface::transformDimensions
  129. */
  130. public function transformDimensions(array &$dimensions, $uri);
  131. /**
  132. * Determines the extension of the derivative without generating it.
  133. *
  134. * @param string $extension
  135. * The file extension of the original image.
  136. *
  137. * @return string
  138. * The extension the derivative image will have, given the extension of the
  139. * original.
  140. */
  141. public function getDerivativeExtension($extension);
  142. /**
  143. * Returns a specific image effect.
  144. *
  145. * @param string $effect
  146. * The image effect ID.
  147. *
  148. * @return \Drupal\image\ImageEffectInterface
  149. * The image effect object.
  150. */
  151. public function getEffect($effect);
  152. /**
  153. * Returns the image effects for this style.
  154. *
  155. * @return \Drupal\image\ImageEffectPluginCollection|\Drupal\image\ImageEffectInterface[]
  156. * The image effect plugin collection.
  157. */
  158. public function getEffects();
  159. /**
  160. * Saves an image effect for this style.
  161. *
  162. * @param array $configuration
  163. * An array of image effect configuration.
  164. *
  165. * @return string
  166. * The image effect ID.
  167. */
  168. public function addImageEffect(array $configuration);
  169. /**
  170. * Deletes an image effect from this style.
  171. *
  172. * @param \Drupal\image\ImageEffectInterface $effect
  173. * The image effect object.
  174. *
  175. * @return $this
  176. */
  177. public function deleteImageEffect(ImageEffectInterface $effect);
  178. /**
  179. * Determines if this style can be applied to a given image.
  180. *
  181. * @param string $uri
  182. * The URI of the image.
  183. *
  184. * @return bool
  185. * TRUE if the image is supported, FALSE otherwise.
  186. */
  187. public function supportsUri($uri);
  188. }