class ImageFactory (View source)

Provides a factory for image objects.

Properties

protected ImageToolkitManager $toolkitManager

The image toolkit plugin manager.

protected string $toolkitId

The image toolkit ID to use for this factory.

Methods

__construct(ImageToolkitManager $toolkit_manager)

Constructs a new ImageFactory object.

$this
setToolkitId(string $toolkit_id)

Sets the ID of the image toolkit.

string
getToolkitId()

Gets the ID of the image toolkit currently in use.

get(string|null $source = NULL, string|null $toolkit_id = NULL)

Constructs a new Image object.

array
getSupportedExtensions(string|null $toolkit_id = NULL)

Returns the image file extensions supported by the toolkit.

Details

__construct(ImageToolkitManager $toolkit_manager)

Constructs a new ImageFactory object.

Parameters

ImageToolkitManager $toolkit_manager

The image toolkit plugin manager.

$this setToolkitId(string $toolkit_id)

Sets the ID of the image toolkit.

Parameters

string $toolkit_id

The ID of the image toolkit to use for this image factory.

Return Value

$this

string getToolkitId()

Gets the ID of the image toolkit currently in use.

Return Value

string

The ID of the image toolkit in use by the image factory.

ImageInterface get(string|null $source = NULL, string|null $toolkit_id = NULL)

Constructs a new Image object.

Normally, the toolkit set as default in the admin UI is used by the factory to create new Image objects. This can be overridden through \Drupal\Core\Image\ImageInterface::setToolkitId() so that any new Image object created will use the new toolkit specified. Finally, a single Image object can be created using a specific toolkit, regardless of the current factory settings, by passing its plugin ID in the $toolkit_id argument.

Parameters

string|null $source

(optional) The path to an image file, or NULL to construct the object with no image source.

string|null $toolkit_id

(optional) The ID of the image toolkit to use for this image, or NULL to use the current toolkit.

Return Value

ImageInterface

An Image object.

See also

ImageFactory::setToolkitId

array getSupportedExtensions(string|null $toolkit_id = NULL)

Returns the image file extensions supported by the toolkit.

Parameters

string|null $toolkit_id

(optional) The ID of the image toolkit to use for checking, or NULL to use the current toolkit.

Return Value

array

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

See also

ImageToolkitInterface::getSupportedExtensions