Changeset 16973


Ignore:
Timestamp:
Jul 24, 2012, 3:38:35 PM (8 years ago)
Author:
plg
Message:

compatibility with Piwigo 2.4

ability to use jpegtran with $confrotate_image_jpegtran = true : lossless photo rotation

Location:
extensions/rotateImage
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/rotateImage/language/en_UK/plugin.lang.php

    r13319 r16973  
    44$lang['Angle'] = 'Angle';
    55$lang['Also rotate HD image'] = 'Also rotate HD image';
    6 $lang['90° right'] = '90° right';
    7 $lang['90° left'] = '90° left';
     6$lang['90° right'] = '90° clockwise';
     7$lang['90° left'] = '90° counter-clockwise';
    88$lang['180°'] = '180°';
    99$lang['auto (EXIF orientation tag)'] = 'auto (EXIF orientation tag)';
  • extensions/rotateImage/language/fr_FR/plugin.lang.php

    r13319 r16973  
    44$lang['Angle'] = 'Angle';
    55$lang['Also rotate HD image'] = 'Pivoter aussi l\'image HD';
    6 $lang['90° right'] = '90° à droite';
    7 $lang['90° left'] = '90° à gauche';
     6$lang['90° right'] = '90° dans le sens des aiguilles d\'une montre';
     7$lang['90° left'] = '90° dans le sens inverse des aiguilles d\'une montre';
    88$lang['180°'] = '180°';
    99$lang['auto (EXIF orientation tag)'] = 'automatique (selon le tag d\'orientation EXIF)';
  • extensions/rotateImage/main.inc.php

    r13524 r16973  
    22/*
    33Plugin Name: Rotate Image
    4 Version: 0.6
     4Version: auto
    55Description: enables to rotate images in batch processing
    66Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=578
     
    88if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    99
    10 add_event_handler('loc_begin_element_set_global', 'rotate_image_set_template_data');
    1110add_event_handler('ws_add_methods', 'add_image_rotate_method');
    12 add_event_handler('element_set_global_action', 'rotate_image_element_action', 50, 2);
    13 
    1411function add_image_rotate_method($arr)
    1512{
     
    1714}
    1815
     16add_event_handler('loc_begin_element_set_global', 'rotate_image_set_template_data');
    1917function rotate_image_set_template_data() {
    2018  global $template,$lang;
    2119  load_language('plugin.lang', dirname(__FILE__).'/');
     20
     21  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
     22
    2223  $angles = array (
    23     array('value' => 90, 'name' => l10n('90° left')),
    2424    array('value' => 270, 'name' => l10n('90° right')),
     25    array('value' =>  90, 'name' => l10n('90° left')),
    2526    array('value' => 180, 'name' => l10n('180°'))
    2627  );
     
    4041}
    4142
     43add_event_handler('element_set_global_action', 'rotate_image_element_action', 50, 2);
    4244function rotate_image_element_action($action, $collection) {
    43   global $template;
    4445  if ($action == 'rotateImg') {
    45     //flush thumbnails links by regenerating ramdom ids to uris
    46     $template->delete_compiled_templates();
     46    add_event_handler('get_derivative_url', 'rotate_image_force_refresh', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
    4747  }
    4848}
    4949
     50function rotate_image_force_refresh($root_url, $params, $src_image, $rel_url)
     51{
     52  global $collection;
     53
     54  if (in_array($src_image->id, $collection))
     55  {
     56    if (strpos($root_url, '?') === false)
     57    {
     58      $root_url.= '?';
     59    }
     60    else
     61    {
     62      $root_url.= '&';
     63    }
     64
     65    $root_url.= 'rand='.md5(uniqid(rand(), true));
     66  }
     67
     68  return $root_url;
     69}
    5070?>
  • extensions/rotateImage/rotate_image.tpl

    r13319 r16973  
    2626
    2727  jQuery('#applyAction').click(function(e) {
    28     if (elements.length != 0)
    29     {
     28    if (typeof(elements) != "undefined") {
    3029      return true;
    3130    }
    32     else if (jQuery('[name="selectAction"]').val() == 'rotateImg')
     31    if (jQuery('[name="selectAction"]').val() == 'rotateImg')
    3332    {
    3433      angle = jQuery('select[name="rotate_angle"]').val();
     
    4039      return true;
    4140    }
     41
    4242    jQuery('.bulkAction').hide();
    4343    jQuery('#regenerationText').html(rotateImagesMessage);
     
    4949      maxRequests: maxRequests
    5050    });
     51
     52    elements = Array();
    5153    if (jQuery('input[name="setSelected"]').attr('checked'))
    5254      elements = all_elements;
     
    8385        },
    8486        dataType: 'json',
    85         success: ( function(data) { progress(++todo, progressBar_max, data['result']) }),
    86         error: ( function(data) { progress(++todo, progressBar_max, false) })
     87        success: ( function(data) { progressRotate(++todo, progressBar_max, data['result']) }),
     88        error: ( function(data) { progressRotate(++todo, progressBar_max, false) })
    8789      });
    8890    }
    8991    return false;
    9092  });
     93
     94  function progressRotate(val, max, success) {
     95    jQuery('#progressBar').progressBar(val, {
     96      max: max,
     97      textFormat: 'fraction',
     98      boxImage: 'themes/default/images/progressbar.gif',
     99      barImage: 'themes/default/images/progressbg_orange.gif'
     100    });
     101    type = success ? 'regenerateSuccess': 'regenerateError'
     102    s = jQuery('[name="'+type+'"]').val();
     103    jQuery('[name="'+type+'"]').val(++s);
     104
     105    if (val == max)
     106      jQuery('#applyAction').click();
     107  }
     108
    91109});
    92110{/literal}{/footer_script}
  • extensions/rotateImage/ws_functions.inc.php

    r13524 r16973  
    11<?php
    2 
    32if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    43
     
    3433  }
    3534
    36   include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
     35  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    3736  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
     37
    3838  $image_id=(int)$params['image_id'];
    3939 
    4040  $query='
    41 SELECT id, path, tn_ext, has_high
     41SELECT
     42    id,
     43    path,
     44    representative_ext,
     45    rotation
    4246  FROM '.IMAGES_TABLE.'
    4347  WHERE id = '.$image_id.'
    4448;';
    45   $image = pwg_db_fetch_assoc(pwg_query($query));
    46   if ($image == null)
     49  $row = pwg_db_fetch_assoc(pwg_query($query));
     50  if ($row == null)
    4751  {
    4852    return new PwgError(403, "image_id not found");
    4953  }
    5054
    51   // rotation angle
    52   if ('auto' == $params['angle']) {
    53     $angle = $params['angle'];
     55  $base_angle = pwg_image::get_rotation_angle_from_code($row['rotation']);
     56
     57  if (get_boolean($params['rotate_hd'])) {
     58    if ('auto' == $angle) {
     59      $angle = pwg_image::get_rotation_angle($row['path']);
     60      $rotation_code = 0;
     61    }
     62    else {
     63      // the angle is based on what the user sees (the thumbnail) and not on
     64      // the original, which may have a different angle
     65      $angle = ($base_angle + $params['angle']) % 360;
     66
     67      // the derivatives must not be rotated
     68      $rotation_code = 4;
     69    }
     70
     71    if (isset($conf['rotate_image_jpegtran']) and $conf['rotate_image_jpegtran']) {
     72      $angle = ($angle + 180) % 360;
     73      $command = 'jpegtran -copy all -rotate '.$angle.' -outfile '.$row['path'].' '.$row['path'];
     74      exec($command);
     75    }
     76    else {
     77      $image = new pwg_image($row['path']);
     78      $image->set_compression_quality(98);
     79      $image->rotate($angle);
     80      $image->write($row['path']);
     81    }
     82
     83    $conf['use_exif'] = false;
     84    $conf['use_iptc'] = false;
     85    sync_metadata(array($row['id']));
     86
     87    single_update(
     88      IMAGES_TABLE,
     89      array('rotation' => $rotation_code),
     90      array('id' => $row['id'])
     91    );
    5492  }
    55   else {
    56     $angle = (int)$params['angle'];
     93  elseif ('auto' != $params['angle']) {
     94    $new_angle = ($base_angle + $params['angle']) % 360;
     95    $rotation_code = pwg_image::get_rotation_code_from_angle($new_angle);
     96
     97    // to show that it's a manual rotation, we use 4,5,6,7 instead of 0,1,2,3
     98    $rotation_code+= 4;
     99
     100    single_update(
     101      IMAGES_TABLE,
     102      array('rotation' => $rotation_code),
     103      array('id' => $row['id'])
     104    );
    57105  }
    58106
    59   if (get_boolean($params['rotate_hd']) and get_boolean($image['has_high'])) {
    60     $to_rotate_path = file_path_for_type($image['path'], 'high');
    61     $quality = $conf['upload_form_hd_quality'];
    62     $regenerate_websize = true;
    63 
    64     if ('auto' == $angle) {
    65       $angle = pwg_image::get_rotation_angle($to_rotate_path);
    66     }
    67   }
    68   else {
    69     $to_rotate_path = $image['path'];
    70     $quality = $conf['upload_form_websize_quality'];
    71     $regenerate_websize = false;
    72   }
    73 
    74   $rotated = new pwg_image($to_rotate_path);
    75   $rotated->set_compression_quality($quality);
    76   $rotated->rotate($angle);
    77   $rotated->write($to_rotate_path);
    78 
    79   if ($regenerate_websize) {
    80     ws_images_resizewebsize(
    81       array(
    82         'image_id' => $params['image_id'],
    83         'maxwidth' => $conf['upload_form_websize_maxwidth'],
    84         'maxheight' => $conf['upload_form_websize_maxheight'],
    85         'quality' => $conf['upload_form_websize_quality'],
    86         'automatic_rotation' => $conf['upload_form_automatic_rotation'],
    87         'library' => $conf['graphics_library'],
    88         ),
    89       $service
    90       );
    91   }
    92 
    93   ws_images_resizethumbnail(
    94     array(
    95       'image_id' => $params['image_id'],
    96       'maxwidth' => $conf['upload_form_thumb_maxwidth'],
    97       'maxheight' => $conf['upload_form_thumb_maxheight'],
    98       'quality' => $conf['upload_form_thumb_quality'],
    99       'crop' => $conf['upload_form_thumb_crop'],
    100       'follow_orientation' => $conf['upload_form_thumb_follow_orientation'],
    101       'library' => $conf['graphics_library'],
    102       ),
    103     $service
    104     );
    105 
    106   $conf['use_exif'] = false;
    107   $conf['use_iptc'] = false;
    108   update_metadata(array($image['id'] => $image['path']));
     107  delete_element_derivatives($row);
    109108 
    110109  return true;
Note: See TracChangeset for help on using the changeset viewer.