You are here

interface ImageToolkitInterface in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php \Drupal\Core\ImageToolkit\ImageToolkitInterface

Defines an interface for image toolkits.

An image toolkit provides common image file manipulations like scaling, cropping, and rotating.

Hierarchy

Expanded class hierarchy of ImageToolkitInterface

All classes that implement ImageToolkitInterface

See also

\Drupal\Core\ImageToolkit\Annotation\ImageToolkit

\Drupal\Core\ImageToolkit\ImageToolkitBase

\Drupal\Core\ImageToolkit\ImageToolkitManager

Plugin API

Related topics

3 files declare their use of ImageToolkitInterface
Image.php in core/lib/Drupal/Core/Image/Image.php
ImageTest.php in core/tests/Drupal/Tests/Core/Image/ImageTest.php
ToolkitTest.php in core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php

File

core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php, line 47

Namespace

Drupal\Core\ImageToolkit
View source
interface ImageToolkitInterface extends ContainerFactoryPluginInterface, PluginInspectionInterface, PluginFormInterface {

  /**
   * Sets the source path of the image file.
   *
   * @param string $source
   *   The source path of the image file.
   *
   * @return $this
   *   An instance of the current toolkit object.
   *
   * @throws \BadMethodCallException
   *   After being set initially, the source image cannot be changed.
   */
  public function setSource($source);

  /**
   * Gets the source path of the image file.
   *
   * @return string
   *   The source path of the image file, or an empty string if the source is
   *   not set.
   */
  public function getSource();

  /**
   * Checks if the image is valid.
   *
   * @return bool
   *   TRUE if the image toolkit is currently handling a valid image, FALSE
   *   otherwise.
   */
  public function isValid();

  /**
   * Writes an image resource to a destination file.
   *
   * @param string $destination
   *   A string file URI or path where the image should be saved.
   *
   * @return bool
   *   TRUE on success, FALSE on failure.
   */
  public function save($destination);

  /**
   * Determines if a file contains a valid image.
   *
   * Drupal supports GIF, JPG and PNG file formats when used with the GD
   * toolkit, and may support others, depending on which toolkits are
   * installed.
   *
   * @return bool
   *   TRUE if the file could be found and is an image, FALSE otherwise.
   */
  public function parseFile();

  /**
   * Returns the height of the image.
   *
   * @return int|null
   *   The height of the image, or NULL if the image is invalid.
   */
  public function getHeight();

  /**
   * Returns the width of the image.
   *
   * @return int|null
   *   The width of the image, or NULL if the image is invalid.
   */
  public function getWidth();

  /**
   * Returns the MIME type of the image file.
   *
   * @return string
   *   The MIME type of the image file, or an empty string if the image is
   *   invalid.
   */
  public function getMimeType();

  /**
   * Gets toolkit requirements in a format suitable for hook_requirements().
   *
   * @return array
   *   An associative requirements array as is returned by hook_requirements().
   *   If the toolkit claims no requirements to the system, returns an empty
   *   array. The array can have arbitrary keys and they do not have to be
   *   prefixed by e.g. the module name or toolkit ID, as the system will make
   *   the keys globally unique.
   *
   * @see hook_requirements()
   */
  public function getRequirements();

  /**
   * Verifies that the Image Toolkit is set up correctly.
   *
   * @return bool
   *   TRUE if the toolkit is available on this machine, FALSE otherwise.
   */
  public static function isAvailable();

  /**
   * Returns a list of image file extensions supported by the toolkit.
   *
   * @return array
   *   An array of supported image file extensions (e.g. png/jpeg/gif).
   */
  public static function getSupportedExtensions();

  /**
   * Applies a toolkit operation to an image.
   *
   * @param string $operation
   *   The toolkit operation to be processed.
   * @param array $arguments
   *   An associative array of arguments to be passed to the toolkit
   *   operation, e.g. array('width' => 50, 'height' => 100,
   *   'upscale' => TRUE).
   *
   * @return bool
   *   TRUE if the operation was performed successfully, FALSE otherwise.
   */
  public function apply($operation, array $arguments = []);

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerFactoryPluginInterface::create public static function Creates an instance of the plugin. 120
ImageToolkitInterface::apply public function Applies a toolkit operation to an image. 1
ImageToolkitInterface::getHeight public function Returns the height of the image. 2
ImageToolkitInterface::getMimeType public function Returns the MIME type of the image file. 2
ImageToolkitInterface::getRequirements public function Gets toolkit requirements in a format suitable for hook_requirements(). 1
ImageToolkitInterface::getSource public function Gets the source path of the image file. 1
ImageToolkitInterface::getSupportedExtensions public static function Returns a list of image file extensions supported by the toolkit. 2
ImageToolkitInterface::getWidth public function Returns the width of the image. 2
ImageToolkitInterface::isAvailable public static function Verifies that the Image Toolkit is set up correctly. 2
ImageToolkitInterface::isValid public function Checks if the image is valid. 2
ImageToolkitInterface::parseFile public function Determines if a file contains a valid image. 2
ImageToolkitInterface::save public function Writes an image resource to a destination file. 2
ImageToolkitInterface::setSource public function Sets the source path of the image file. 1
PluginFormInterface::buildConfigurationForm public function Form constructor. 37
PluginFormInterface::submitConfigurationForm public function Form submission handler. 32
PluginFormInterface::validateConfigurationForm public function Form validation handler. 18
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 4
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2