You are here

function _image_build_derivatives in Image 5

Same name and namespace in other branches
  1. 5.2 image.module \_image_build_derivatives()
  2. 6 image.module \_image_build_derivatives()

Generate image derivatives.

2 calls to _image_build_derivatives()
image_prepare in ./image.module
Implementation of hook_prepare().
image_update in ./image.module
Implementation of hook_update

File

./image.module, line 902

Code

function _image_build_derivatives(&$node, $temp = FALSE) {

  // sanity check:
  if (!_image_check_settings()) {
    return FALSE;
  }
  $original_path = file_create_path($node->images[IMAGE_ORIGINAL]);

  // Figure out which sizes we need to generate.
  $all_sizes = image_get_sizes();
  $needed_sizes = image_get_derivative_sizes($original_path);
  $unneeded_sizes = array_diff(array_keys($all_sizes), array_keys($needed_sizes));

  // Images that don't need a derivative image get set to the original.
  foreach ($unneeded_sizes as $key) {
    $node->images[$key] = $original_path;
  }

  // Resize for the necessary sizes.
  foreach ($needed_sizes as $key => $size) {
    $destination = _image_filename($original_path, $key, $temp);
    if (!image_scale($original_path, $destination, $size['width'], $size['height'])) {
      drupal_set_message(t('Unable to create scaled %label image', array(
        '%label' => $size['label'],
      )), 'error');
      return FALSE;
    }

    // Set standard file permissions for webserver-generated files
    @chmod($destination, 0664);
    $node->images[$key] = $destination;
    module_invoke_all('image_alter', $node, $destination, $key);
  }
}