aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2011-04-22 11:34:57 +0000
committerpatdenice <patdenice@piwigo.org>2011-04-22 11:34:57 +0000
commit10ff3f2f06e5f241b14bc48474cc6fc3bc46ae0c (patch)
treee0fdd857a3a307e49177e89550aaa4161e6059c6 /include
parent03c9195f7c846522c21f99f35d01d4054900f343 (diff)
feature:2274
pwg.images.resize method is able to create or regenerate image from image path. git-svn-id: http://piwigo.org/svn/trunk@10563 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/ws_functions.inc.php71
1 files changed, 47 insertions, 24 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 674ac8c6b..4f302a427 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -2673,6 +2673,11 @@ function ws_images_resize($params, &$service)
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)
@@ -2681,32 +2686,50 @@ function ws_images_resize($params, &$service)
$params[$param] = $conf['upload_form_'.$type.'_'.$param];
}
- $query='
+ include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
+
+ if (!empty($params['image_id']))
+ {
+ $query='
SELECT id, path, tn_ext, has_high
-FROM '.IMAGES_TABLE.'
-WHERE id = '.(int)$params['image_id'].'
+ FROM '.IMAGES_TABLE.'
+ WHERE id = '.(int)$params['image_id'].'
;';
- $image = pwg_db_fetch_assoc(pwg_query($query));
+ $image = pwg_db_fetch_assoc(pwg_query($query));
+
+ if ($image == null)
+ {
+ return new PwgError(403, "image_id not found");
+ }
- if ($image == null)
+ $image_path = $image['path'];
+ $thumb_path = get_thumbnail_path($image);
+ $hd_path = get_high_path($image);
+ }
+ else
{
- return new PwgError(403, "image_id not found");
+ $image_path = $params['image_path'];
+ $thumb_path = file_path_for_type($image_path, 'thumb');
+ $hd_path = file_path_for_type($image_path, 'high');
}
- include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
-
- if (!is_valid_image_extension(get_extension($image['path'])))
+ 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']))
+ $result = false;
+
+ if ($params['type'] == 'thumbnail' and file_exists($image_path))
{
- trigger_event(
+ prepare_directory(dirname($thumb_path));
+
+ $result = trigger_event(
'upload_thumbnail_resize',
false,
- $image['path'],
- get_thumbnail_path($image),
+ $image_path,
+ $thumb_path,
$params['maxwidth'],
$params['maxheight'],
$params['quality'],
@@ -2714,28 +2737,28 @@ WHERE id = '.(int)$params['image_id'].'
get_boolean($params['crop']),
get_boolean($params['follow_orientation'])
);
- return true;
}
- elseif (!empty($image['has_high']))
+ elseif (file_exists($hd_path))
{
- trigger_event(
+ $result = trigger_event(
'upload_image_resize',
false,
- file_path_for_type($image['path'], 'high'),
- $image['path'],
+ $hd_path,
+ $image_path,
$params['maxwidth'],
$params['maxheight'],
$params['quality'],
false
);
- $conf['use_exif'] = false;
- $conf['use_iptc'] = false;
- update_metadata(array($image['id'] => $image['path']));
-
- return true;
+ if (!empty($image['has_high']))
+ {
+ $conf['use_exif'] = false;
+ $conf['use_iptc'] = false;
+ update_metadata(array($image['id'] => $image['path']));
+ }
}
- return false;
+ return $result;
}
function ws_extensions_update($params, &$service)