From 17a04fcd399965f5589b26245ac040969d5ac117 Mon Sep 17 00:00:00 2001 From: patdenice Date: Thu, 21 Apr 2011 22:35:16 +0000 Subject: feature:2273 Add crop functionality to webservice and batch manager. git-svn-id: http://piwigo.org/svn/trunk@10553 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/batch_manager_global.php | 40 ++++++++++++++-------- .../default/template/batch_manager_global.tpl | 39 +++++++++++++++++++-- include/ws_functions.inc.php | 8 +++-- ws.php | 4 ++- 4 files changed, 71 insertions(+), 20 deletions(-) diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php index 5b61bc9e8..40628d0d7 100644 --- a/admin/batch_manager_global.php +++ b/admin/batch_manager_global.php @@ -417,7 +417,7 @@ SELECT id, path if ($_POST['regenerateError'] != '0') array_push($page['warnings'], sprintf(l10n('%s thumbnails can not be regenerated'), $_POST['regenerateError'])); - $update_fields = array('thumb_maxwidth', 'thumb_maxheight', 'thumb_quality'); + $update_fields = array('thumb_maxwidth', 'thumb_maxheight', 'thumb_quality', 'thumb_crop', 'thumb_follow_orientation'); } if ('regenerateWebsize' == $action) @@ -437,26 +437,38 @@ SELECT id, path $updates = array(); foreach ($update_fields as $field) { - $value = null; - if (!empty($_POST[$field])) + if (is_bool($upload_form_config[$field]['default'])) { - $value = $_POST[$field]; - } + $value = isset($_POST[$field]); - if (preg_match($upload_form_config[$field]['pattern'], $value) - and $value >= $upload_form_config[$field]['min'] - and $value <= $upload_form_config[$field]['max']) - { - $conf['upload_form_'.$field] = $value; - $updates[] = array( + $updates[] = array( 'param' => 'upload_form_'.$field, - 'value' => $value + 'value' => boolean_to_string($value) ); } else { - $updates = null; - break; + $value = null; + if (!empty($_POST[$field])) + { + $value = $_POST[$field]; + } + + if (preg_match($upload_form_config[$field]['pattern'], $value) + and $value >= $upload_form_config[$field]['min'] + and $value <= $upload_form_config[$field]['max']) + { + $conf['upload_form_'.$field] = $value; + $updates[] = array( + 'param' => 'upload_form_'.$field, + 'value' => $value + ); + } + else + { + $updates = null; + break; + } } $form_values[$field] = $value; } diff --git a/admin/themes/default/template/batch_manager_global.tpl b/admin/themes/default/template/batch_manager_global.tpl index 66feb44e1..bf7eef6cb 100644 --- a/admin/themes/default/template/batch_manager_global.tpl +++ b/admin/themes/default/template/batch_manager_global.tpl @@ -36,6 +36,11 @@ var selectedMessage_none = "{'No photo selected, %d photos in current set'|@tran var selectedMessage_all = "{'All %d photos are selected'|@translate}"; var regenerateThumbnailsMessage = "{'Thumbnails generation in progress...'|@translate}"; var regenerateWebsizeMessage = "{'Photos generation in progress...'|@translate}"; + +var width_str = '{'Width'|@translate}'; +var height_str = '{'Height'|@translate}'; +var max_width_str = '{'Maximum Width'|@translate}'; +var max_height_str = '{'Maximum Height'|@translate}'; {literal} function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); @@ -333,6 +338,8 @@ $(document).ready(function() { maxwidth = jQuery('input[name="thumb_maxwidth"]').val(); maxheight = jQuery('input[name="thumb_maxheight"]').val(); regenerationText = regenerateThumbnailsMessage; + crop = jQuery('input[name="thumb_crop"]').is(':checked'); + follow_orientation = jQuery('input[name="thumb_follow_orientation"]').is(':checked'); } else if(jQuery('[name="selectAction"]').val() == 'regenerateWebsize') { @@ -341,6 +348,8 @@ $(document).ready(function() { maxwidth = jQuery('input[name="websize_maxwidth"]').val(); maxheight = jQuery('input[name="websize_maxheight"]').val(); regenerationText = regenerateWebsizeMessage; + crop = false; + follow_orientation = false; } else return true; @@ -385,6 +394,8 @@ $(document).ready(function() { type: type, maxwidth: maxwidth, maxheight: maxheight, + crop: crop, + follow_orientation: follow_orientation, image_id: elements[i], format: 'json' }, @@ -396,6 +407,22 @@ $(document).ready(function() { return false; }); + function toggleCropFields(prefix) { + if (jQuery("#"+prefix+"_crop").is(':checked')) { + jQuery("#"+prefix+"_width_th").text(width_str); + jQuery("#"+prefix+"_height_th").text(height_str); + jQuery("#"+prefix+"_follow_orientation_tr").show(); + } + else { + jQuery("#"+prefix+"_width_th").text(max_width_str); + jQuery("#"+prefix+"_height_th").text(max_height_str); + jQuery("#"+prefix+"_follow_orientation_tr").hide(); + } + } + + toggleCropFields("thumb"); + jQuery("#thumb_crop").click(function () {toggleCropFields("thumb")}); + checkPermitAction() }); @@ -661,11 +688,19 @@ jQuery(window).load(function() {
- + + + + + + + + + - + diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 2646abbe0..674ac8c6b 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -2673,11 +2673,11 @@ function ws_images_resize($params, &$service) return new PwgError(403, 'Unknown type (only "thumbnail" or "websize" are accepted'); } - $resize_params = array('maxwidth', 'maxheight', 'quality'); + $resize_params = array('maxwidth', 'maxheight', 'quality', 'crop', 'follow_orientation'); $type = $params['type'] == 'thumbnail' ? 'thumb' : 'websize'; foreach ($resize_params as $param) { - if (empty($params[$param])) + if (empty($params[$param]) and isset($conf['upload_form_'.$type.'_'.$param])) $params[$param] = $conf['upload_form_'.$type.'_'.$param]; } @@ -2710,7 +2710,9 @@ WHERE id = '.(int)$params['image_id'].' $params['maxwidth'], $params['maxheight'], $params['quality'], - true + true, + get_boolean($params['crop']), + get_boolean($params['follow_orientation']) ); return true; } diff --git a/ws.php b/ws.php index 46429b021..fe428120c 100644 --- a/ws.php +++ b/ws.php @@ -412,11 +412,13 @@ function ws_addDefaultMethods( $arr ) 'type' => array('default' => 'thumbnail'), 'maxwidth' => array('default' => null), 'maxheight' => array('default' => null), + 'crop' => array('default' => null), + 'follow_orientation' => array('default' => null), 'quality' => array('default' => null), ), 'Regenerate thumbnails or websize photo with given arguments.
Argument "type" can be "thumbnail" or "websize". Default is "thumbnail". -
If maxwidth, maxheight or quality are missing, default parameters of upload will be used.' +
If maxwidth, maxheight, crop, follow_orientation or quality are missing, default parameters of upload will be used.' ); $service->addMethod( -- cgit v1.2.3
{'Maximum Width'|@translate}
{'Maximum Width'|@translate} {'pixels'|@translate}
{'Maximum Height'|@translate}{'Maximum Height'|@translate} {'pixels'|@translate}