function imagecache_build_derivative in ImageCache 5.2
Same name and namespace in other branches
- 6.2 imagecache.module \imagecache_build_derivative()
build an image cache derivative
Parameters
$actions Array of imagecache actions.:
$src Path of the source file.:
$dst Path of the destination file.:
$tmp Path of the temporary file used for manipulating the image.:
Return value
true - derivative generated, false - no derivative generated, null - derivative being generated
2 calls to imagecache_build_derivative()
- imagecache_image_alter in ./
imagecache_image.module - Implementation of hook_image_alter()
- _imagecache_cache in ./
imagecache.module - handle request validation and responses to imagecache requests.
File
- ./
imagecache.module, line 458 - Dynamic image resizer and image cacher.
Code
function imagecache_build_derivative($actions, $src, $dst) {
// get the folder for the final location of this preset...
$dir = dirname($dst);
// Build the destination folder tree if it doesn't already exists.
if (!file_check_directory($dir) && !mkdir($dir, 0775, true)) {
watchdog('imagecache', t('Failed to create imagecache directory: %dir', array(
'%dir' => $dir,
)), WATCHDOG_ERROR);
return false;
}
if (!($image = imageapi_image_open($src))) {
return false;
}
foreach ($actions as $action) {
if (!empty($action['data'])) {
// QuickSketch, why do these run first/twice? - dopry.
if (isset($action['data']['width'])) {
$width = _imagecache_filter('width', $action['data']['width'], $image->info['width'], $image->info['height']);
}
if (isset($action['data']['height'])) {
$height = _imagecache_filter('height', $action['data']['height'], $image->info['width'], $image->info['height']);
}
foreach ($action['data'] as $key => $value) {
$action['data'][$key] = _imagecache_filter($key, $value, $image->info['width'], $image->info['height'], $width, $height);
}
}
if (!_imagecache_apply_action($action, $image)) {
watchdog('imagecache', t('action(id:%id): %action failed for %src', array(
'%id' => $action['actionid'],
'%action' => $action['action'],
'%src' => $src,
)), WATCHDOG_ERROR);
return false;
}
}
if (!imageapi_image_close($image, $dst)) {
if (file_exists($dst)) {
watchdog('imagecache', t('Cached image file already exists. There is an issue with your Rewrite configuration.'), WATCHDOG_ERROR);
}
return false;
}
return true;
}