ImageInterface
interface ImageInterface (View source)
Provides an interface for image objects.
Methods
Checks if the image is valid.
Returns the height of the image.
Returns the width of the image.
Returns the size of the image file.
Returns the MIME type of the image file.
Retrieves the source path of the image file.
Returns the image toolkit used for this image file.
Returns the ID of the image toolkit used for this image file.
Applies a toolkit operation to the image.
Closes the image and saves the changes to a file.
Prepares a new image, without loading it from a file.
Scales an image while maintaining aspect ratio.
Scales an image to the exact width and height given.
Instructs the toolkit to save the image in the format specified by the extension.
Crops an image to a rectangle specified by the given dimensions.
Resizes an image to the given dimensions (ignoring aspect ratio).
Converts an image to grayscale.
Rotates an image by the given number of degrees.
Details
bool
isValid()
Checks if the image is valid.
int|null
getHeight()
Returns the height of the image.
int|null
getWidth()
Returns the width of the image.
int|null
getFileSize()
Returns the size of the image file.
string
getMimeType()
Returns the MIME type of the image file.
string
getSource()
Retrieves the source path of the image file.
ImageToolkitInterface
getToolkit()
Returns the image toolkit used for this image file.
string
getToolkitId()
Returns the ID of the image toolkit used for this image file.
bool
apply(string $operation, array $arguments = [])
Applies a toolkit operation to the image.
The operation is deferred to the active toolkit.
bool
save(string|null $destination = NULL)
Closes the image and saves the changes to a file.
bool
createNew(int $width, int $height, string $extension = 'png', string $transparent_color = '#ffffff')
Prepares a new image, without loading it from a file.
For a working example, see \Drupal\system\Plugin\ImageToolkit\Operation\gd\CreateNew.
bool
scale(int|null $width, int|null $height = NULL, bool $upscale = FALSE)
Scales an image while maintaining aspect ratio.
The resulting image can be smaller for one or both target dimensions.
bool
scaleAndCrop(int $width, int $height)
Scales an image to the exact width and height given.
This function achieves the target aspect ratio by cropping the original image equally on both sides, or equally on the top and bottom. This function is useful to create uniform sized avatars from larger images.
The resulting image always has the exact target dimensions.
bool
convert(string $extension)
Instructs the toolkit to save the image in the format specified by the extension.
bool
crop(int $x, int $y, int $width, int $height = NULL)
Crops an image to a rectangle specified by the given dimensions.
bool
resize(int $width, int $height)
Resizes an image to the given dimensions (ignoring aspect ratio).
bool
desaturate()
Converts an image to grayscale.
bool
rotate(float $degrees, string|null $background = NULL)
Rotates an image by the given number of degrees.