1. drupal
    1. 8
    2. 7
8 – 7 image_style_create_derivative($style, $source, $destination)

Creates a new image derivative based on an image style.

Generates an image derivative by creating the destination folder (if it does not already exist), applying all image effects defined in $style['effects'], and saving a cached version of the resulting image.


$style An image style array.

$source Path of the source file.

$destination Path or URI of the destination file.

Return value

TRUE if an image derivative was generated, or FALSE if the image derivative could not be generated.

See also


▾ 2 functions call image_style_create_derivative()

image_style_deliver in modules/image/image.module
Menu callback; Given a style and image path, generate a derivative.
theme_image_style_preview in modules/image/
Returns HTML for a preview of an image style.


modules/image/image.module, line 786

function image_style_create_derivative($style, $source, $destination) {
  // Get the folder for the final location of this style.
  $directory = drupal_dirname($destination);

  // Build the destination folder tree if it doesn't already exist.
  if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
    watchdog('image', 'Failed to create style directory: %directory', array('%directory' => $directory), WATCHDOG_ERROR);
    return FALSE;

  if (!$image = image_load($source)) {
    return FALSE;

  foreach ($style['effects'] as $effect) {
    image_effect_apply($image, $effect);

  if (!image_save($image, $destination)) {
    if (file_exists($destination)) {
      watchdog('image', 'Cached image file %destination already exists. There may be an issue with your rewrite configuration.', array('%destination' => $destination), WATCHDOG_ERROR);
    return FALSE;

  return TRUE;