function _image_build_derivatives in Image 6
Same name and namespace in other branches
- 5.2 image.module \_image_build_derivatives()
- 5 image.module \_image_build_derivatives()
Generate image derivatives.
Parameters
$node: The node.
$temp: Boolean indicating if the derivatives should be saved to the temp directory.
Return value
New array of images for the node.
2 calls to _image_build_derivatives()
- image_form_validate in ./
image.module - image_update in ./
image.module - Implementation of hook_update().
File
- ./
image.module, line 837
Code
function _image_build_derivatives($node, $temp = 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.
$images[IMAGE_ORIGINAL] = $original_path;
foreach ($unneeded_sizes as $key) {
$images[$key] = $original_path;
}
// Resize for the necessary sizes.
$image_info = image_get_info($original_path);
foreach ($needed_sizes as $key => $size) {
$destination = _image_filename($original_path, $key, $temp);
$status = FALSE;
switch ($size['operation']) {
// Depending on the operation, the image will be scaled or resized & cropped
case 'scale':
$status = image_scale($original_path, $destination, $size['width'], $size['height']);
break;
case 'scale_crop':
$status = image_scale_and_crop($original_path, $destination, $size['width'], $size['height']);
break;
}
if (!$status) {
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);
$images[$key] = $destination;
module_invoke_all('image_alter', $node, $destination, $key);
}
return $images;
}