ImageEffectInterface.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Drupal\image;
  3. use Drupal\Component\Plugin\ConfigurablePluginInterface;
  4. use Drupal\Component\Plugin\PluginInspectionInterface;
  5. use Drupal\Core\Image\ImageInterface;
  6. /**
  7. * Defines the interface for image effects.
  8. *
  9. * @see \Drupal\image\Annotation\ImageEffect
  10. * @see \Drupal\image\ImageEffectBase
  11. * @see \Drupal\image\ConfigurableImageEffectInterface
  12. * @see \Drupal\image\ConfigurableImageEffectBase
  13. * @see \Drupal\image\ImageEffectManager
  14. * @see plugin_api
  15. */
  16. interface ImageEffectInterface extends PluginInspectionInterface, ConfigurablePluginInterface {
  17. /**
  18. * Applies an image effect to the image object.
  19. *
  20. * @param \Drupal\Core\Image\ImageInterface $image
  21. * An image file object.
  22. *
  23. * @return bool
  24. * TRUE on success. FALSE if unable to perform the image effect on the image.
  25. */
  26. public function applyEffect(ImageInterface $image);
  27. /**
  28. * Determines the dimensions of the styled image.
  29. *
  30. * @param array &$dimensions
  31. * Dimensions to be modified - an array with the following keys:
  32. * - width: the width in pixels, or NULL if unknown
  33. * - height: the height in pixels, or NULL if unknown
  34. * When either of the dimensions are NULL, the corresponding HTML attribute
  35. * will be omitted when an image style using this image effect is used.
  36. * @param string $uri
  37. * Original image file URI. It is passed in to allow an effect to
  38. * optionally use this information to retrieve additional image metadata
  39. * to determine dimensions of the styled image.
  40. * ImageEffectInterface::transformDimensions key objective is to calculate
  41. * styled image dimensions without performing actual image operations, so
  42. * be aware that performing IO on the URI may lead to decrease in
  43. * performance.
  44. */
  45. public function transformDimensions(array &$dimensions, $uri);
  46. /**
  47. * Returns the extension of the derivative after applying this image effect.
  48. *
  49. * @param string $extension
  50. * The file extension the derivative has before applying.
  51. *
  52. * @return string
  53. * The file extension after applying.
  54. */
  55. public function getDerivativeExtension($extension);
  56. /**
  57. * Returns a render array summarizing the configuration of the image effect.
  58. *
  59. * @return array
  60. * A render array.
  61. */
  62. public function getSummary();
  63. /**
  64. * Returns the image effect label.
  65. *
  66. * @return string
  67. * The image effect label.
  68. */
  69. public function label();
  70. /**
  71. * Returns the unique ID representing the image effect.
  72. *
  73. * @return string
  74. * The image effect ID.
  75. */
  76. public function getUuid();
  77. /**
  78. * Returns the weight of the image effect.
  79. *
  80. * @return int|string
  81. * Either the integer weight of the image effect, or an empty string.
  82. */
  83. public function getWeight();
  84. /**
  85. * Sets the weight for this image effect.
  86. *
  87. * @param int $weight
  88. * The weight for this image effect.
  89. *
  90. * @return $this
  91. */
  92. public function setWeight($weight);
  93. }