You are here

function node_gallery_batch_rotate_callback in Node Gallery 6.3

1 string reference to 'node_gallery_batch_rotate_callback'
node_gallery_manage_images_submit in ./node_gallery.pages.inc

File

./node_gallery.inc, line 1084
Shared functions for node_gallery

Code

function node_gallery_batch_rotate_callback($filepath, $degrees, &$context) {
  $result = 0;
  $image = imageapi_image_open($filepath);
  if ($image !== FALSE) {
    if (imageapi_default_toolkit() == 'imageapi_imagemagick') {
      $result = imageapi_image_rotate($image, $degrees, 0x0);
    }
    else {
      $result = imageapi_image_rotate($image, $degrees);
    }
    global $conf;
    $conf['imageapi_jpeg_quality'] = 100;
    imageapi_image_close($image);
    imagecache_image_flush($filepath);

    // add a _r$i to the filename for cache distinction of rotated images
    $filepath_new = preg_replace_callback('~(?:_r([0-9]+))?(?=(?:\\.[^./]*)?$)~', create_function('$matches', 'return "_r".(!empty($matches[1]) ? $matches[1]+1 : 1);'), $filepath, 1);
    $file = (object) field_file_load($filepath);
    $file->timestamp = time();
    $file->filepath = $filepath_new;
    $file->filename = basename($filepath_new);
    $filepath_old = $filepath;
    file_move($filepath, $filepath_new);
    drupal_write_record('files', $file, 'fid');
  }
  else {
    watchdog('node_gallery', 'Could not open image for rotation');
  }
  $context['results'][] = $result;
}