diff options
author | patdenice <patdenice@piwigo.org> | 2011-04-29 17:38:59 +0000 |
---|---|---|
committer | patdenice <patdenice@piwigo.org> | 2011-04-29 17:38:59 +0000 |
commit | 0db141fc62c90de376a2658868a0c3f42f45395b (patch) | |
tree | ba4bb2c2704ff27ec1606a08772389e201e31b3a | |
parent | 4f8e0b54acae2ee65f6f2cdebcb8e830064febb5 (diff) |
feature:2259
Create two different methods in webservice to create/regenerate thumbnail and to regenerate websize.
git-svn-id: http://piwigo.org/svn/trunk@10686 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/include/image.class.php | 2 | ||||
-rw-r--r-- | admin/themes/default/template/batch_manager_global.tpl | 7 | ||||
-rw-r--r-- | admin/themes/default/template/thumbnail.tpl | 3 | ||||
-rw-r--r-- | include/ws_functions.inc.php | 112 | ||||
-rw-r--r-- | ws.php | 36 |
5 files changed, 88 insertions, 72 deletions
diff --git a/admin/include/image.class.php b/admin/include/image.class.php index 0fa851636..64c485887 100644 --- a/admin/include/image.class.php +++ b/admin/include/image.class.php @@ -290,7 +290,7 @@ class pwg_image if (is_null($library))
{
- $library = $conf['image_library'];
+ $library = $conf['graphics_library'];
}
// Choose image library
diff --git a/admin/themes/default/template/batch_manager_global.tpl b/admin/themes/default/template/batch_manager_global.tpl index abf4eb97e..96f7f42a7 100644 --- a/admin/themes/default/template/batch_manager_global.tpl +++ b/admin/themes/default/template/batch_manager_global.tpl @@ -333,7 +333,7 @@ $(document).ready(function() { } else if (jQuery('[name="selectAction"]').val() == 'regenerateThumbnails') { - type = 'thumbnail'; + resizeMethod = 'pwg.images.resizeThumbnail'; maxRequests = 3; maxwidth = jQuery('input[name="thumb_maxwidth"]').val(); maxheight = jQuery('input[name="thumb_maxheight"]').val(); @@ -343,7 +343,7 @@ $(document).ready(function() { } else if(jQuery('[name="selectAction"]').val() == 'regenerateWebsize') { - type = 'websize'; + resizeMethod = 'pwg.images.resizeWebsize'; maxRequests = 1; maxwidth = jQuery('input[name="websize_maxwidth"]').val(); maxheight = jQuery('input[name="websize_maxheight"]').val(); @@ -390,8 +390,7 @@ $(document).ready(function() { type: 'GET', url: 'ws.php', data: { - method: 'pwg.images.resize', - type: type, + method: resizeMethod, maxwidth: maxwidth, maxheight: maxheight, crop: crop, diff --git a/admin/themes/default/template/thumbnail.tpl b/admin/themes/default/template/thumbnail.tpl index 5e981c3ef..8a2dec411 100644 --- a/admin/themes/default/template/thumbnail.tpl +++ b/admin/themes/default/template/thumbnail.tpl @@ -30,9 +30,8 @@ function processThumbs(width,height,crop,follow_orientation) { type: 'GET', url: 'ws.php', data: { - method: 'pwg.images.resize', + method: 'pwg.images.resizeThumbnail', image_path: image_path, - type: 'thumbnail', maxwidth: width, maxheight: height, crop: crop, diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index ecaa9585d..08c3394af 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -2658,34 +2658,18 @@ function ws_themes_performAction($params, &$service) } } -function ws_images_resize($params, &$service) +function ws_images_resizethumbnail($params, &$service) { - global $conf; - if (!is_admin()) { return new PwgError(401, 'Access denied'); } - if (!in_array($params['type'], array('thumbnail', 'websize'))) - { - return new PwgError(403, 'Unknown type (only "thumbnail" or "websize" are accepted'); - } - if (empty($params['image_id']) and empty($params['image_path'])) { return new PwgError(403, "image_id or image_path is missing"); } - $resize_params = array('maxwidth', 'maxheight', 'quality', 'crop', 'follow_orientation'); - $type = $params['type'] == 'thumbnail' ? 'thumb' : 'websize'; - foreach ($resize_params as $param) - { - if (empty($params[$param]) and isset($conf['upload_form_'.$type.'_'.$param])) - $params[$param] = $conf['upload_form_'.$type.'_'.$param]; - } - - include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); @@ -2705,63 +2689,87 @@ SELECT id, path, tn_ext, has_high $image_path = $image['path']; $thumb_path = get_thumbnail_path($image); - $hd_path = get_high_path($image); } else { $image_path = $params['image_path']; $thumb_path = file_path_for_type($image_path, 'thumb'); - $hd_path = file_path_for_type($image_path, 'high'); } - if (!is_valid_image_extension(get_extension($image_path))) + if (!file_exists($image_path) or !is_valid_image_extension(get_extension($image_path))) { return new PwgError(403, "image can't be resized"); } $result = false; + prepare_directory(dirname($thumb_path)); + $img = new pwg_image($image_path, $params['library']); + + $result = $img->pwg_resize( + $thumb_path, + $params['maxwidth'], + $params['maxheight'], + $params['quality'], + false, // automatic rotation is not needed for thumbnails. + true, // strip metadata + get_boolean($params['crop']), + get_boolean($params['follow_orientation']) + ); - if ($params['type'] == 'thumbnail' and file_exists($image_path)) + $img->destroy(); + return $result; +} + +function ws_images_resizewebsize($params, &$service) +{ + if (!is_admin()) { - prepare_directory(dirname($thumb_path)); + return new PwgError(401, 'Access denied'); + } - $img = new pwg_image($image_path, $params['library']); + include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); + include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); + include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); - $result = $img->pwg_resize( - $thumb_path, - $params['maxwidth'], - $params['maxheight'], - $params['quality'], - $params['automatic_rotation'], - true, - get_boolean($params['crop']), - get_boolean($params['follow_orientation']) - ); + $query=' +SELECT id, path, tn_ext, has_high + FROM '.IMAGES_TABLE.' + WHERE id = '.(int)$params['image_id'].' +;'; + $image = pwg_db_fetch_assoc(pwg_query($query)); - $img->destroy(); + if ($image == null) + { + return new PwgError(403, "image_id not found"); } - elseif (file_exists($hd_path)) + + $image_path = $image['path']; + $hd_path = get_high_path($image); + + if (empty($image['has_high']) or !file_exists($hd_path) or !is_valid_image_extension(get_extension($image_path))) { - $img = new pwg_image($hd_path); + return new PwgError(403, "image can't be resized"); + } - $result = $img->pwg_resize( - $image_path, - $params['maxwidth'], - $params['maxheight'], - $params['quality'], - $params['automatic_rotation'], - false - ); + $result = false; + $img = new pwg_image($hd_path); + + $result = $img->pwg_resize( + $image_path, + $params['maxwidth'], + $params['maxheight'], + $params['quality'], + $params['automatic_rotation'], + false // strip metadata + ); - $img->destroy(); + $img->destroy(); + + global $conf; + $conf['use_exif'] = false; + $conf['use_iptc'] = false; + update_metadata(array($image['id'] => $image['path'])); - if (!empty($image['has_high'])) - { - $conf['use_exif'] = false; - $conf['use_iptc'] = false; - update_metadata(array($image['id'] => $image['path'])); - } - } return $result; } @@ -405,25 +405,35 @@ function ws_addDefaultMethods( $arr ) ); $service->addMethod( - 'pwg.images.resize', - 'ws_images_resize', + 'pwg.images.resizeThumbnail', + 'ws_images_resizethumbnail', array( 'image_id' => array('default' => null), 'image_path' => array('default' => null), - 'type' => array('default' => 'thumbnail'), + 'maxwidth' => array('default' => $conf['upload_form_thumb_maxwidth']), + 'maxheight' => array('default' => $conf['upload_form_thumb_maxheight']), + 'quality' => array('default' => $conf['upload_form_thumb_quality']), + 'crop' => array('default' => $conf['upload_form_thumb_crop']), + 'follow_orientation' => array('default' => $conf['upload_form_thumb_follow_orientation']), + 'library' => array('default' => $conf['graphics_library']), + ), + 'Create/Regenerate thumbnails photo with given arguments. +<br>One of arguments "image_id" or "image_path" must be sent.' + ); + + $service->addMethod( + 'pwg.images.resizeWebsize', + 'ws_images_resizewebsize', + array( + 'image_id' => array(), + 'maxwidth' => array('default' => $conf['upload_form_websize_maxwidth']), + 'maxheight' => array('default' => $conf['upload_form_websize_maxheight']), + 'quality' => array('default' => $conf['upload_form_websize_quality']), 'automatic_rotation' => array('default' => $conf['upload_form_automatic_rotation']), 'library' => array('default' => $conf['graphics_library']), - 'maxwidth' => array('default' => null), - 'maxheight' => array('default' => null), - 'crop' => array('default' => null), - 'follow_orientation' => array('default' => null), - 'quality' => array('default' => null), ), - 'Create/Regenerate thumbnails or websize photo with given arguments. -<br>One of arguments "image_id" or "image_path" must be passed filled. -<br>Argument "type" can be "thumbnail" or "websize". Default is "thumbnail". -<br>If maxwidth, maxheight, crop, follow_orientation or quality are missing, default parameters of upload will be used.' -); + 'Regenerate websize photo with given arguments.' + ); $service->addMethod( 'pwg.extensions.update', |