ImageEffectInterface.php 3.1 KB

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