3 namespace Drupal\Core\Image;
6 * Provides an interface for image objects.
8 interface ImageInterface {
11 * Checks if the image is valid.
14 * TRUE if the image object contains a valid image, FALSE otherwise.
16 public function isValid();
19 * Returns the height of the image.
22 * The height of the image, or NULL if the image is invalid.
24 public function getHeight();
27 * Returns the width of the image.
30 * The width of the image, or NULL if the image is invalid.
32 public function getWidth();
35 * Returns the size of the image file.
38 * The size of the file in bytes, or NULL if the image is invalid.
40 public function getFileSize();
43 * Returns the MIME type of the image file.
46 * The MIME type of the image file, or an empty string if the image is
49 public function getMimeType();
52 * Retrieves the source path of the image file.
55 * The source path of the image file. An empty string if the source is
58 public function getSource();
61 * Returns the image toolkit used for this image file.
63 * @return \Drupal\Core\ImageToolkit\ImageToolkitInterface
66 public function getToolkit();
69 * Returns the ID of the image toolkit used for this image file.
72 * The ID of the image toolkit.
74 public function getToolkitId();
77 * Applies a toolkit operation to the image.
79 * The operation is deferred to the active toolkit.
81 * @param string $operation
82 * The operation to be performed against the image.
83 * @param array $arguments
84 * (optional) An associative array of arguments to be passed to the toolkit
85 * operation; for instance,
87 * ['width' => 50, 'height' => 100, 'upscale' => TRUE]
89 * Defaults to an empty array.
92 * TRUE on success, FALSE on failure.
94 public function apply($operation, array $arguments = []);
97 * Closes the image and saves the changes to a file.
99 * @param string|null $destination
100 * (optional) Destination path where the image should be saved. If it is empty
101 * the original image file will be overwritten.
104 * TRUE on success, FALSE on failure.
106 * @see \Drupal\Core\ImageToolkit\ImageToolkitInterface::save()
108 public function save($destination = NULL);
111 * Prepares a new image, without loading it from a file.
113 * For a working example, see
114 * \Drupal\system\Plugin\ImageToolkit\Operation\gd\CreateNew.
117 * The width of the new image, in pixels.
119 * The height of the new image, in pixels.
120 * @param string $extension
121 * (optional) The extension of the image file (for instance, 'png', 'gif',
122 * etc.). Allowed values depend on the implementation of the image toolkit.
124 * @param string $transparent_color
125 * (optional) The hexadecimal string representing the color to be used
126 * for transparency, needed for GIF images. Defaults to '#ffffff' (white).
129 * TRUE on success, FALSE on failure.
131 public function createNew($width, $height, $extension = 'png', $transparent_color = '#ffffff');
134 * Scales an image while maintaining aspect ratio.
136 * The resulting image can be smaller for one or both target dimensions.
138 * @param int|null $width
139 * The target width, in pixels. If this value is null then the scaling will
140 * be based only on the height value.
141 * @param int|null $height
142 * (optional) The target height, in pixels. If this value is null then the
143 * scaling will be based only on the width value.
144 * @param bool $upscale
145 * (optional) Boolean indicating that files smaller than the dimensions will
146 * be scaled up. This generally results in a low quality image.
149 * TRUE on success, FALSE on failure.
151 public function scale($width, $height = NULL, $upscale = FALSE);
154 * Scales an image to the exact width and height given.
156 * This function achieves the target aspect ratio by cropping the original
157 * image equally on both sides, or equally on the top and bottom. This
158 * function is useful to create uniform sized avatars from larger images.
160 * The resulting image always has the exact target dimensions.
163 * The target width, in pixels.
165 * The target height, in pixels.
168 * TRUE on success, FALSE on failure.
170 public function scaleAndCrop($width, $height);
173 * Instructs the toolkit to save the image in the format specified by the
176 * @param string $extension
177 * The extension to convert to (for instance, 'jpeg' or 'png'). Allowed
178 * values depend on the current image toolkit.
181 * TRUE on success, FALSE on failure.
183 * @see \Drupal\Core\ImageToolkit\ImageToolkitInterface::getSupportedExtensions()
185 public function convert($extension);
188 * Crops an image to a rectangle specified by the given dimensions.
191 * The top left coordinate, in pixels, of the crop area (x axis value).
193 * The top left coordinate, in pixels, of the crop area (y axis value).
195 * The target width, in pixels.
197 * The target height, in pixels.
200 * TRUE on success, FALSE on failure.
202 public function crop($x, $y, $width, $height = NULL);
205 * Resizes an image to the given dimensions (ignoring aspect ratio).
208 * The target width, in pixels.
210 * The target height, in pixels.
213 * TRUE on success, FALSE on failure.
215 public function resize($width, $height);
218 * Converts an image to grayscale.
221 * TRUE on success, FALSE on failure.
223 public function desaturate();
226 * Rotates an image by the given number of degrees.
228 * @param float $degrees
229 * The number of (clockwise) degrees to rotate the image.
230 * @param string|null $background
231 * (optional) An hexadecimal integer specifying the background color to use
232 * for the uncovered area of the image after the rotation; for example,
233 * 0x000000 for black, 0xff00ff for magenta, and 0xffffff for white. When
234 * NULL (the default) is specified, for images that support transparency,
235 * this will default to transparent; otherwise, it will default to white.
238 * TRUE on success, FALSE on failure.
240 public function rotate($degrees, $background = NULL);