Image toolkits

Drupal's image toolkits provide an abstraction layer for common image file manipulations like scaling, cropping, and rotating. The abstraction frees module authors from the need to support multiple image libraries, and it allows site administrators to choose the library that's best for them.

PHP includes the GD library by default so a GD toolkit is installed with Drupal. Other toolkits like ImageMagic are available from contrib modules. GD works well for small images, but using it with larger files may cause PHP to run out of memory. In contrast the ImageMagick library does not suffer from this problem, but it requires the ISP to have installed additional software.

Image toolkits are discovered based on the associated module's hook_image_toolkits. Additionally the image toolkit include file must be identified in the files array in the module.info file. The toolkit must then be enabled using the admin/config/media/image-toolkit form.

Only one toolkit may be selected at a time. If a module author wishes to call a specific toolkit they can check that it is installed by calling image_get_available_toolkits(), and then calling its functions directly.

Functions

NameLocationDescription
image_cropincludes/image.incCrop an image to the rectangle specified by the given rectangle.
image_desaturateincludes/image.incConvert an image to grayscale.
image_gd_check_settingsmodules/system/image.gd.incVerify GD2 settings (that the right version is actually installed).
image_gd_create_tmpmodules/system/image.gd.incCreate a truecolor image preserving transparency from a provided image.
image_gd_cropmodules/system/image.gd.incCrop an image using the GD toolkit.
image_gd_desaturatemodules/system/image.gd.incConvert an image resource to grayscale.
image_gd_get_infomodules/system/image.gd.incGet details about an image.
image_gd_loadmodules/system/image.gd.incGD helper function to create an image resource from a file.
image_gd_resizemodules/system/image.gd.incScale an image to the specified size using GD.
image_gd_rotatemodules/system/image.gd.incRotate an image the given number of degrees.
image_gd_savemodules/system/image.gd.incGD helper to write an image resource to a destination file.
image_gd_settingsmodules/system/image.gd.incRetrieve settings for the GD2 toolkit.
image_gd_settings_validatemodules/system/image.gd.incValidate the submitted GD settings.
image_get_available_toolkitsincludes/image.incReturn a list of available toolkits.
image_get_infoincludes/image.incGet details about an image.
image_get_toolkitincludes/image.incRetrieve the name of the currently used toolkit.
image_loadincludes/image.incLoad an image file and return an image object.
image_resizeincludes/image.incResize an image to the given dimensions (ignoring aspect ratio).
image_rotateincludes/image.incRotate an image by the given number of degrees.
image_saveincludes/image.incClose the image and save the changes to a file.
image_scaleincludes/image.incScales an image to the given width and height while maintaining aspect ratio.
image_scale_and_cropincludes/image.incScales an image to the exact width and height given.
image_toolkit_invokeincludes/image.incInvokes the given method using the currently selected toolkit.
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.