function upload_element_imagecache_action in Upload element 6
Hooks into imageache preset for save action
Parameters
string $presetname Imagecache preset to perfrom on the uploaded image.:
string $path Path to the temp original image file.:
string $dest Path to save the new image to.:
Return value
bool FALSE if there was a problem saving the image, TRUE otherwise.
1 call to upload_element_imagecache_action()
- upload_element_save in ./
upload_element.module - Saves an uploaded file
File
- ./
upload_element.module, line 514 - A module that provides two new elements to the FAPI for file handling.
Code
function upload_element_imagecache_action($presetname, $path, $dst) {
if (!function_exists('imagecache_preset_by_name')) {
return FALSE;
}
if (!($preset = imagecache_preset_by_name($presetname))) {
return FALSE;
}
if (is_file($dst)) {
return TRUE;
}
$src = $path;
if (!is_file($src) && !is_file($src = file_create_path($src))) {
return FALSE;
}
if (!getimagesize($src)) {
return FALSE;
}
$lockfile = file_directory_temp() . '/' . $preset['presetname'] . basename($src);
if (file_exists($lockfile)) {
watchdog('imagecache', 'Imagecache already generating: %dst, Lock file: %tmp.', array(
'%dst' => $dst,
'%tmp' => $lockfile,
), WATCHDOG_NOTICE);
return FALSE;
}
touch($lockfile);
register_shutdown_function('file_delete', realpath($lockfile));
if (file_exists($dst) || imagecache_build_derivative($preset['actions'], $src, $dst)) {
return TRUE;
}
// Generate an error if image could not generate.
watchdog('imagecache', 'Failed generating an image from %image using imagecache preset %preset.', array(
'%image' => $path,
'%preset' => $preset['presetname'],
), WATCHDOG_ERROR);
return FALSE;
}