ImageEffectInterface.php 3.03 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\image\ImageEffectInterface.
 */

namespace Drupal\image;

10
use Drupal\Component\Plugin\ConfigurablePluginInterface;
11
use Drupal\Component\Plugin\PluginInspectionInterface;
12
use Drupal\Core\Image\ImageInterface;
13 14 15

/**
 * Defines the interface for image effects.
16 17 18 19 20 21 22
 *
 * @see \Drupal\image\Annotation\ImageEffect
 * @see \Drupal\image\ImageEffectBase
 * @see \Drupal\image\ConfigurableImageEffectInterface
 * @see \Drupal\image\ConfigurableImageEffectBase
 * @see \Drupal\image\ImageEffectManager
 * @see plugin_api
23
 */
24
interface ImageEffectInterface extends PluginInspectionInterface, ConfigurablePluginInterface {
25 26 27 28

  /**
   * Applies an image effect to the image object.
   *
29 30
   * @param \Drupal\Core\Image\ImageInterface $image
   *   An image file object.
31 32 33 34
   *
   * @return bool
   *   TRUE on success. FALSE if unable to perform the image effect on the image.
   */
35
  public function applyEffect(ImageInterface $image);
36 37 38 39

  /**
   * Determines the dimensions of the styled image.
   *
40 41 42 43 44 45
   * @param array &$dimensions
   *   Dimensions to be modified - an array with the following keys:
   *   - width: the width in pixels, or NULL if unknown
   *   - height: the height in pixels, or NULL if unknown
   *   When either of the dimensions are NULL, the corresponding HTML attribute
   *   will be omitted when an image style using this image effect is used.
46 47 48 49 50 51 52 53
   * @param string $uri
   *   Original image file URI. It is passed in to allow an effect to
   *   optionally use this information to retrieve additional image metadata
   *   to determine dimensions of the styled image.
   *   ImageEffectInterface::transformDimensions key objective is to calculate
   *   styled image dimensions without performing actual image operations, so
   *   be aware that performing IO on the URI may lead to decrease in
   *   performance.
54
   */
55
  public function transformDimensions(array &$dimensions, $uri);
56

57 58 59 60 61 62 63 64 65 66 67 68
  /**
   * Returns the extension the derivative would have have after applying this
   * image effect.
   *
   * @param string $extension
   *   The file extension the derivative has before applying.
   *
   * @return string
   *   The file extension after applying.
   */
  public function getDerivativeExtension($extension);

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  /**
   * Returns a render array summarizing the configuration of the image effect.
   *
   * @return array
   *   A render array.
   */
  public function getSummary();

  /**
   * Returns the image effect label.
   *
   * @return string
   *   The image effect label.
   */
  public function label();

  /**
   * Returns the unique ID representing the image effect.
   *
   * @return string
   *   The image effect ID.
   */
  public function getUuid();

  /**
   * Returns the weight of the image effect.
   *
   * @return int|string
   *   Either the integer weight of the image effect, or an empty string.
   */
  public function getWeight();

  /**
   * Sets the weight for this image effect.
   *
   * @param int $weight
   *   The weight for this image effect.
   *
107
   * @return $this
108 109 110 111
   */
  public function setWeight($weight);

}