diff -u b/core/includes/image.inc b/core/includes/image.inc --- b/core/includes/image.inc +++ b/core/includes/image.inc @@ -38,10 +38,10 @@ /** * Gets a list of available toolkits. * - * @return + * @return array * An array with the toolkit names as keys and the descriptions as values. */ -function image_get_available_toolkits($key = NULL) { +function image_get_available_toolkits() { // Use plugin system to get list of available toolkits. $toolkits = drupal_container()->get('image.toolkit.manager')->getDefinitions(); @@ -57,9 +57,13 @@ } /** - * Gets the name of the currently used toolkit. + * Gets an image toolkit. * - * @return + * @param $toolkit_id + * (optional) String specifying toolkit to load. NULL will load the default + * toolkit. + * + * @return Drupal\system\Plugin\ImageToolkitInterface * Object of the default toolkit, or FALSE on error. */ function image_get_toolkit($toolkit_id = NULL) { @@ -94,12 +98,12 @@ * toolkit, and may support others, depending on which toolkits are * installed. * - * @param $filepath + * @param string $filepath * String specifying the path of the image file. - * @param $toolkit - * An optional image toolkit object to override the default. + * @param Drupal\system\Plugin\ImageToolkitInterface $toolkit + * (optional) An image toolkit object to override the default. * - * @return + * @return stdClass * FALSE, if the file could not be found or is not an image. Otherwise, a * keyed array containing information about the image: * - "width": Width, in pixels. @@ -108,13 +112,13 @@ * - "mime_type": MIME type ('image/jpeg', 'image/gif', 'image/png'). * - "file_size": File size in bytes. */ -function image_get_info($filepath, $toolkit = FALSE) { +function image_get_info($filepath, Drupal\system\Plugin\ImageToolkitInterface $toolkit = NULL) { $details = FALSE; if (!is_file($filepath) && !is_uploaded_file($filepath)) { return $details; } - if (!$toolkit) { + if ($toolkit === NULL) { $toolkit = image_get_toolkit(); } if ($toolkit) { @@ -139,14 +143,14 @@ * * The resulting image always has the exact target dimensions. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $width + * @param int $width * The target width, in pixels. - * @param $height + * @param int $height * The target height, in pixels. * - * @return + * @return bool * TRUE on success, FALSE on failure. * * @see image_load() @@ -169,20 +173,21 @@ * * The resulting dimensions can be smaller for one or both target dimensions. * - * @param $dimensions + * @param array $dimensions * Dimensions to be modified - an array with components width and height, in * pixels. - * @param $width - * The target width, in pixels. If this value is NULL then the scaling will be - * based only on the height value. - * @param $height - * The target height, in pixels. If this value is NULL then the scaling will - * be based only on the width value. - * @param $upscale - * Boolean indicating that images smaller than the target dimensions will be - * scaled up. This generally results in a low quality image. + * @param int $width + * (optional) The target width, in pixels. If this value is NULL then the + * scaling will be based only on the height value. + * @param int $height + * (optional) The target height, in pixels. If this value is NULL then the + * scaling will be based only on the width value. + * @param bool $upscale + * (optional) Boolean indicating that images smaller than the target + * dimensions will be scaled up. This generally results in a low quality + * image. * - * @return + * @return bool * TRUE if $dimensions was modified, FALSE otherwise. * * @see image_scale() @@ -217,19 +222,19 @@ * * The resulting image can be smaller for one or both target dimensions. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $width - * The target width, in pixels. This value is omitted then the scaling will - * based only on the height value. - * @param $height - * The target height, in pixels. This value is omitted then the scaling will - * based only on the width value. - * @param $upscale - * Boolean indicating that files smaller than the dimensions will be scaled - * up. This generally results in a low quality image. + * @param int $width + * (optional) The target width, in pixels. This value is omitted then the + * scaling will based only on the height value. + * @param int $height + * (optional) The target height, in pixels. This value is omitted then the + * scaling will based only on the width value. + * @param bool $upscale + * (optional) Boolean indicating that files smaller than the dimensions will + * be scaled up. This generally results in a low quality image. * - * @return + * @return bool * TRUE on success, FALSE on failure. * * @see image_dimensions_scale() @@ -250,14 +255,14 @@ /** * Resizes an image to the given dimensions (ignoring aspect ratio). * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $width + * @param int $width * The target width, in pixels. - * @param $height + * @param int $height * The target height, in pixels. * - * @return + * @return bool * TRUE on success, FALSE on failure. * * @see image_load() @@ -273,18 +278,18 @@ /** * Rotates an image by the given number of degrees. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $degrees + * @param int $degrees * The number of (clockwise) degrees to rotate the image. - * @param $background - * An hexadecimal integer specifying the background color to use for the - * uncovered area of the image after the rotation. E.g. 0x000000 for black, - * 0xff00ff for magenta, and 0xffffff for white. For images that support - * transparency, this will default to transparent. Otherwise it will + * @param string $background + * (optional) An hexadecimal integer specifying the background color to use + * for the uncovered area of the image after the rotation. E.g. 0x000000 for + * black, 0xff00ff for magenta, and 0xffffff for white. For images that + * support transparency, this will default to transparent. Otherwise it will * be white. * - * @return + * @return bool * TRUE on success, FALSE on failure. * * @see image_load() @@ -297,18 +302,18 @@ /** * Crops an image to a rectangle specified by the given dimensions. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $x + * @param int $x * The top left coordinate, in pixels, of the crop area (x axis value). - * @param $y + * @param int $y * The top left coordinate, in pixels, of the crop area (y axis value). - * @param $width + * @param int $width * The target width, in pixels. - * @param $height + * @param int $height * The target height, in pixels. * - * @return + * @return bool * TRUE on success, FALSE on failure. * * @see image_load() @@ -329,10 +334,10 @@ /** * Converts an image to grayscale. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). * - * @return + * @return bool * TRUE on success, FALSE on failure. * * @see image_load() @@ -347,12 +352,12 @@ * * Any changes to the file are not saved until image_save() is called. * - * @param $file + * @param string $file * Path to an image file. - * @param $toolkit - * An optional, image toolkit object to override the default. + * @param Drupal\system\Plugin\ImageToolkitInterface $toolkit + * (optional) Image toolkit object to override the default. * - * @return + * @return stdClass * An image object or FALSE if there was a problem loading the file. The * image object has the following properties: * - 'source' - The original file path. @@ -367,8 +372,8 @@ * @see image_get_available_toolkits() * @see image_gd_load() */ -function image_load($file, $toolkit = FALSE) { - if (!$toolkit) { +function image_load($file, Drupal\system\Plugin\ImageToolkitInterface $toolkit = NULL) { + if ($toolkit === NULL) { $toolkit = image_get_toolkit(); } if ($toolkit) { @@ -388,14 +393,14 @@ /** * Closes the image and saves the changes to a file. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). The object's 'info' property * will be updated if the file is saved successfully. * @param $destination - * Destination path where the image should be saved. If it is empty the - * original image file will be overwritten. + * (optional) Destination path where the image should be saved. If it is empty + * the original image file will be overwritten. * - * @return + * @return bool * TRUE on success, FALSE on failure. * * @see image_load() diff -u b/core/modules/image/image.effects.inc b/core/modules/image/image.effects.inc --- b/core/modules/image/image.effects.inc +++ b/core/modules/image/image.effects.inc @@ -64,20 +64,20 @@ /** * Image effect callback; Resize an image resource. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $data + * @param array $data * An array of attributes to use when performing the resize effect with the * following items: * - "width": An integer representing the desired width in pixels. * - "height": An integer representing the desired height in pixels. * - * @return + * @return bool * TRUE on success. FALSE on failure to resize image. * * @see image_resize() */ -function image_resize_effect(&$image, $data) { +function image_resize_effect(stdClass &$image, array $data) { if (!image_resize($image, $data['width'], $data['height'])) { watchdog('image', 'Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit->getPluginId(), '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR); return FALSE; @@ -88,10 +88,10 @@ /** * Image dimensions callback; Resize. * - * @param $dimensions + * @param array $dimensions * Dimensions to be modified - an array with components width and height, in * pixels. - * @param $data + * @param array $data * An array of attributes to use when performing the resize effect with the * following items: * - "width": An integer representing the desired width in pixels. @@ -106,9 +106,9 @@ /** * Image effect callback; Scale an image resource. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $data + * @param array $data * An array of attributes to use when performing the scale effect with the * following items: * - "width": An integer representing the desired width in pixels. @@ -116,12 +116,12 @@ * - "upscale": A boolean indicating that the image should be upscaled if the * dimensions are larger than the original image. * - * @return + * @return bool * TRUE on success. FALSE on failure to scale image. * * @see image_scale() */ -function image_scale_effect(&$image, $data) { +function image_scale_effect(stdClass &$image, array $data) { // Set sane default values. $data += array( 'width' => NULL, @@ -139,10 +139,10 @@ /** * Image dimensions callback; Scale. * - * @param $dimensions + * @param array $dimensions * Dimensions to be modified - an array with components width and height, in * pixels. - * @param $data + * @param array $data * An array of attributes to use when performing the scale effect with the * following items: * - "width": An integer representing the desired width in pixels. @@ -159,9 +159,9 @@ /** * Image effect callback; Crop an image resource. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $data + * @param array $data * An array of attributes to use when performing the crop effect with the * following items: * - "width": An integer representing the desired width in pixels. @@ -170,11 +170,13 @@ * of "XOFFSET-YOFFSET". XOFFSET is either a number of pixels or * "left", "center", "right" and YOFFSET is either a number of pixels or * "top", "center", "bottom". - * @return + * + * @return bool * TRUE on success. FALSE on failure to crop image. + * * @see image_crop() */ -function image_crop_effect(&$image, $data) { +function image_crop_effect(stdClass &$image, array $data) { // Set sane default values. $data += array( 'anchor' => 'center-center', @@ -193,18 +195,20 @@ /** * Image effect callback; Scale and crop an image resource. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $data + * @param array $data * An array of attributes to use when performing the scale and crop effect * with the following items: * - "width": An integer representing the desired width in pixels. * - "height": An integer representing the desired height in pixels. - * @return + * + * @return bool * TRUE on success. FALSE on failure to scale and crop image. + * * @see image_scale_and_crop() */ -function image_scale_and_crop_effect(&$image, $data) { +function image_scale_and_crop_effect(stdClass &$image, array $data) { if (!image_scale_and_crop($image, $data['width'], $data['height'])) { watchdog('image', 'Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit->getPluginId(), '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR); return FALSE; @@ -215,15 +219,17 @@ /** * Image effect callback; Desaturate (grayscale) an image resource. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $data + * @param array $data * An array of attributes to use when performing the desaturate effect. - * @return + * + * @return bool * TRUE on success. FALSE on failure to desaturate image. + * * @see image_desaturate() */ -function image_desaturate_effect(&$image, $data) { +function image_desaturate_effect(stdClass &$image, array $data) { if (!image_desaturate($image)) { watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit->getPluginId(), '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR); return FALSE; @@ -234,9 +240,9 @@ /** * Image effect callback; Rotate an image resource. * - * @param $image + * @param stdClass $image * An image object returned by image_load(). - * @param $data + * @param array $data * An array of attributes to use when performing the rotate effect containing * the following items: * - "degrees": The number of (clockwise) degrees to rotate the image. @@ -246,11 +252,13 @@ * - "bgcolor": The background color to use for exposed areas of the image. * Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave * blank for transparency on image types that support it. - * @return + * + * @return bool * TRUE on success. FALSE on failure to rotate image. + * * @see image_rotate(). */ -function image_rotate_effect(&$image, $data) { +function image_rotate_effect(stdClass &$image, array $data) { // Set sane default values. $data += array( 'degrees' => 0, @@ -287,10 +295,10 @@ /** * Image dimensions callback; Rotate. * - * @param $dimensions + * @param array $dimensions * Dimensions to be modified - an array with components width and height, in * pixels. - * @param $data + * @param array $data * An array of attributes to use when performing the rotate effect containing * the following items: * - "degrees": The number of (clockwise) degrees to rotate the image. diff -u b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php --- b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php @@ -34,14 +34,15 @@ /** * Scales an image to the specified size. * - * @param $image + * @param stdClass $image * An image object. The $image->resource, $image->info['width'], and * $image->info['height'] values will be modified by this call. - * @param $width + * @param int $width * The new width of the resized image, in pixels. - * @param $height + * @param int $height * The new height of the resized image, in pixels. - * @return + * + * @return bool * TRUE or FALSE, based on success. * * @see image_resize() @@ -51,18 +52,19 @@ /** * Rotates an image the given number of degrees. * - * @param $image + * @param stdClass $image * An image object. The $image->resource, $image->info['width'], and * $image->info['height'] values will be modified by this call. - * @param $degrees + * @param int $degrees * The number of (clockwise) degrees to rotate the image. - * @param $background - * An hexadecimal integer specifying the background color to use for the - * uncovered area of the image after the rotation. E.g. 0x000000 for black, - * 0xff00ff for magenta, and 0xffffff for white. For images that support - * transparency, this will default to transparent. Otherwise it will + * @param string $background + * (optional) An hexadecimal integer specifying the background color to use + * for the uncovered area of the image after the rotation. E.g. 0x000000 for + * black, 0xff00ff for magenta, and 0xffffff for white. For images that + * support transparency, this will default to transparent. Otherwise it will * be white. - * @return + * + * @return bool * TRUE or FALSE, based on success. * * @see image_rotate() @@ -72,18 +74,19 @@ /** * Crops an image. * - * @param $image + * @param stdClass $image * An image object. The $image->resource, $image->info['width'], and * $image->info['height'] values will be modified by this call. - * @param $x + * @param int $x * The starting x offset at which to start the crop, in pixels. - * @param $y + * @param int $y * The starting y offset at which to start the crop, in pixels. - * @param $width + * @param int $width * The width of the cropped area, in pixels. - * @param $height + * @param int $height * The height of the cropped area, in pixels. - * @return + * + * @return bool * TRUE or FALSE, based on success. * * @see image_crop() @@ -96,8 +99,10 @@ * Note that transparent GIFs loose transparency when desaturated. * * @param $image - * An image object. The $image->resource value will be modified by this call. - * @return + * An image object. The $image->resource value will be modified by this + * call. + * + * @return bool * TRUE or FALSE, based on success. * * @see image_desaturate() @@ -107,9 +112,10 @@ /** * Creates an image resource from a file. * - * @param $image + * @param stdClass $image * An image object. The $image->resource value will populated by this call. - * @return + * + * @return bool * TRUE or FALSE, based on success. * * @see image_load() @@ -119,11 +125,12 @@ /** * Writes an image resource to a destination file. * - * @param $image + * @param stdClass $image * An image object. - * @param $destination + * @param string $destination * A string file URI or path where the image should be saved. - * @return + * + * @return bool * TRUE or FALSE, based on success. * * @see image_save() @@ -133,9 +140,10 @@ /** * Gets details about an image. * - * @param $image + * @param stdClass $image * An image object. - * @return + * + * @return mixed * FALSE, if the file could not be found or is not an image. Otherwise, a * keyed array containing information about the image: * - "width": Width, in pixels. @@ -150,8 +158,8 @@ /** * Verifies Image Toolkit is set up correctly. * - * @return - * A boolean indicating if the GD toolkit is available on this machine. + * @return bool + * True if the GD toolkit is available on this machine. */ static function isAvailable(); } diff -u b/core/modules/system/lib/Drupal/system/Plugin/system/imagetoolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/system/imagetoolkit/GDToolkit.php --- b/core/modules/system/lib/Drupal/system/Plugin/system/imagetoolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/system/imagetoolkit/GDToolkit.php @@ -236,14 +236,14 @@ /** * Creates a truecolor image preserving transparency from a provided image. * - * @param $image + * @param stdClass $image * An image object. - * @param $width + * @param int $width * The new width of the new image, in pixels. - * @param $height + * @param int $height * The new height of the new image, in pixels. * - * @return + * @return resource * A GD image handle. */ public function createTmp(stdClass $image, $width, $height) { diff -u b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/system/imagetoolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/system/imagetoolkit/TestToolkit.php --- b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/system/imagetoolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/system/imagetoolkit/TestToolkit.php @@ -97,10 +97,10 @@ /** * Stores the values passed to a toolkit call. * - * @param $op + * @param string $op * One of the image toolkit operations: 'get_info', 'load', 'save', * 'settings', 'resize', 'rotate', 'crop', 'desaturate'. - * @param $args + * @param array $args * Values passed to hook. * * @see image_test_get_all_calls()