function node_gallery_api_batch_rotate in Node Gallery 7
Batch API rotate callback.
1 string reference to 'node_gallery_api_batch_rotate'
- node_gallery_api_manage_items_submit in ./
node_gallery_api.pages.inc - Submit handler for Manage Items form.
File
- ./
node_gallery_api.inc, line 439 - Node Gallery API function
Code
function node_gallery_api_batch_rotate($fid, $degrees, &$context) {
$result = 0;
$file = file_load($fid);
$filepath_new = preg_replace_callback('~(?:_r([0-9]+))?(?=(?:\\.[^./]*)?$)~', function ($matches) {
return "_r" . (!empty($matches[1]) ? $matches[1] + 1 : 1);
}, $file->uri, 1);
$new_file = file_move($file, $filepath_new);
$image = image_load($new_file->uri);
global $conf;
$conf['image_jpeg_quality'] = 100;
if ($image !== FALSE) {
if ($image->toolkit == 'imagemagick') {
$result = image_rotate($image, $degrees, 0x0);
}
else {
$result = image_rotate($image, $degrees);
}
image_save($image);
$width = !empty($image->width) ? $image->width : !empty($image->info['width']) ? $image->info['width'] : NULL;
$height = !empty($image->height) ? $image->height : !empty($image->info['height']) ? $image->info['height'] : NULL;
$new_file->image_dimensions['width'] = $width;
$new_file->image_dimensions['height'] = $height;
file_save($new_file);
image_path_flush($image->source);
}
else {
watchdog('node_gallery', 'Could not open image for rotation');
}
$context['results'][] = $result;
}