Community Documentation

Image toolkits

  1. drupal
    1. 6 image.inc
    2. 7 image.inc
    3. 8 image.inc

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 installed by copying the image.ToolkitName.inc file into Drupal's includes directory. The toolkit must then be enabled using the admin/settings/image-toolkit form.

Only one toolkit maybe 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 & methods

NameDescription
image_cropCrop an image to the rectangle specified by the given rectangle.
image_gd_check_settingsVerify GD2 settings (that the right version is actually installed).
image_gd_closeGD helper to write an image resource to a destination file.
image_gd_cropCrop an image using the GD toolkit.
image_gd_infoRetrieve information about the toolkit.
image_gd_openGD helper function to create an image resource from a file.
image_gd_resizeScale an image to the specified size using GD.
image_gd_rotateRotate an image the given number of degrees.
image_gd_settingsRetrieve settings for the GD2 toolkit.
image_gd_settings_validateValidate the submitted GD settings.
image_get_available_toolkitsReturn a list of available toolkits.
image_get_infoGet details about an image.
image_get_toolkitRetrieve the name of the currently used toolkit.
image_resizeResize an image to the given dimensions (ignoring aspect ratio).
image_rotateRotate an image by the given number of degrees.
image_scaleScales an image to the given width and height while maintaining aspect ratio.
image_scale_and_cropScales an image to the exact width and height given. Achieves the target aspect ratio by cropping the original image equally on both sides, or equally on the top and bottom. This function is, for example, useful to create uniform sized avatars from…
image_toolkit_invokeInvokes the given method using the currently selected toolkit.

File

includes/image.inc, line 8
API for manipulating images.

Login or register to post comments