interface ImageToolkitInterface implements ContainerFactoryPluginInterface, PluginInspectionInterface, PluginFormInterface (View source)

Defines an interface for image toolkits.

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

Methods

create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

array
buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

$this
setSource(string $source)

Sets the source path of the image file.

string
getSource()

Gets the source path of the image file.

bool
isValid()

Checks if the image is valid.

bool
save(string $destination)

Writes an image resource to a destination file.

bool
parseFile()

Determines if a file contains a valid image.

int|null
getHeight()

Returns the height of the image.

int|null
getWidth()

Returns the width of the image.

string
getMimeType()

Returns the MIME type of the image file.

array
getRequirements()

Gets toolkit requirements in a format suitable for hook_requirements().

static bool
isAvailable()

Verifies that the Image Toolkit is set up correctly.

static array
getSupportedExtensions()

Returns a list of image file extensions supported by the toolkit.

bool
apply(string $operation, array $arguments = [])

Applies a toolkit operation to an image.

Details

static ContainerFactoryPluginInterface create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

Parameters

ContainerInterface $container

The container to pull out services used in the plugin.

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin ID for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

Return Value

ContainerFactoryPluginInterface

Returns an instance of this plugin.

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

array buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and

array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form

An associative array containing the initial structure of the plugin form.

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return Value

array

The form structure.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

$this setSource(string $source)

Sets the source path of the image file.

Parameters

string $source

The source path of the image file.

Return Value

$this

An instance of the current toolkit object.

Exceptions

BadMethodCallException

string getSource()

Gets the source path of the image file.

Return Value

string

The source path of the image file, or an empty string if the source is not set.

bool isValid()

Checks if the image is valid.

Return Value

bool

TRUE if the image toolkit is currently handling a valid image, FALSE otherwise.

bool save(string $destination)

Writes an image resource to a destination file.

Parameters

string $destination

A string file URI or path where the image should be saved.

Return Value

bool

TRUE on success, FALSE on failure.

bool parseFile()

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 Value

bool

TRUE if the file could be found and is an image, FALSE otherwise.

int|null getHeight()

Returns the height of the image.

Return Value

int|null

The height of the image, or NULL if the image is invalid.

int|null getWidth()

Returns the width of the image.

Return Value

int|null

The width of the image, or NULL if the image is invalid.

string getMimeType()

Returns the MIME type of the image file.

Return Value

string

The MIME type of the image file, or an empty string if the image is invalid.

array getRequirements()

Gets toolkit requirements in a format suitable for hook_requirements().

Return Value

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 also

hook_requirements()

static bool isAvailable()

Verifies that the Image Toolkit is set up correctly.

Return Value

bool

TRUE if the toolkit is available on this machine, FALSE otherwise.

static array getSupportedExtensions()

Returns a list of image file extensions supported by the toolkit.

Return Value

array

An array of supported image file extensions (e.g. png/jpeg/gif).

bool apply(string $operation, array $arguments = [])

Applies a toolkit operation to an image.

Parameters

string $operation

The toolkit operation to be processed.

array $arguments

An associative array of arguments to be passed to the toolkit operation, e.g. array('width' => 50, 'height' => 100, 'upscale' => TRUE).

Return Value

bool

TRUE if the operation was performed successfully, FALSE otherwise.