aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2011-04-10 08:59:02 +0000
committerpatdenice <patdenice@piwigo.org>2011-04-10 08:59:02 +0000
commit89803639acb3e3a57ed3b6fcbecb4db0d80bde06 (patch)
treedd313ddcdec2bfeb37bd5e94e1f00f09094fd284
parent2d20fe461a795a42bc5216b8f933bf86ee9c7df7 (diff)
feature:2259
Add web service method: pwg.images.resize git-svn-id: http://piwigo.org/svn/trunk@10235 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--include/ws_functions.inc.php72
-rw-r--r--ws.php15
2 files changed, 87 insertions, 0 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 3f322cf61..a2442530f 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -2658,4 +2658,76 @@ function ws_themes_performAction($params, &$service)
return true;
}
}
+
+function ws_images_resize($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');
+ }
+
+ $resize_params = array('maxwidth', 'maxheight', 'quality');
+ $type = $params['type'] == 'thumbnail' ? 'thumb' : 'websize';
+ foreach ($resize_params as $param)
+ {
+ if (empty($params[$param]))
+ $params[$param] = $conf['upload_form_'.$type.'_'.$param];
+ }
+
+ $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));
+
+ if ($image == null)
+ {
+ return new PwgError(403, "image_id not found");
+ }
+
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
+
+ if (!is_valid_image_extension(get_extension($image['path'])))
+ {
+ return new PwgError(403, "image can't be resized");
+ }
+
+ if ($params['type'] == 'thumbnail' and !empty($image['tn_ext']))
+ {
+ trigger_event(
+ 'upload_thumbnail_resize',
+ false,
+ $image['path'],
+ get_thumbnail_path($image),
+ $params['maxwidth'],
+ $params['maxheight'],
+ $params['quality'],
+ true
+ );
+ return true;
+ }
+ elseif (!empty($image['has_high']))
+ {
+ trigger_event(
+ 'upload_image_resize',
+ false,
+ file_path_for_type($image['path'], 'high'),
+ $image['path'],
+ $params['maxwidth'],
+ $params['maxheight'],
+ $params['quality'],
+ false
+ );
+ return true;
+ }
+ return false;
+}
?>
diff --git a/ws.php b/ws.php
index 7bc4dc21c..3d0af18d1 100644
--- a/ws.php
+++ b/ws.php
@@ -403,6 +403,21 @@ function ws_addDefaultMethods( $arr )
),
'activate/deactivate/delete/set_default a theme<br>administration status required'
);
+
+ $service->addMethod(
+ 'pwg.images.resize',
+ 'ws_images_resize',
+ array(
+ 'image_id' => array(),
+ 'type' => array('default' => 'thumbnail'),
+ 'maxwidth' => array('default' => null),
+ 'maxheight' => array('default' => null),
+ 'quality' => array('default' => null),
+ ),
+ 'Regenerate thumbnails or websize photo with given arguments.
+<br>Argument "type" can be "thumbnail" or "websize". Default is "thumbnail".
+<br>If maxwidth, maxheight or quality are missing, default parameters of upload will be used.'
+);
}
add_event_handler('ws_add_methods', 'ws_addDefaultMethods');