diff options
Diffstat (limited to '')
-rw-r--r-- | admin/include/functions_upload.inc.php | 23 | ||||
-rw-r--r-- | include/ws_functions.inc.php | 71 | ||||
-rw-r--r-- | ws.php | 6 |
3 files changed, 72 insertions, 28 deletions
diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index ce0fafeb4..022d99e46 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -556,6 +556,7 @@ function pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width return false; } + $starttime = get_moment(); $gd_info = gd_info(); // extension of the picture filename @@ -645,11 +646,21 @@ function pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width imagedestroy($destination_image); // everything should be OK if we are here! - return true; + return array( + 'source' => $source_filepath, + 'destination' => $destination_filepath, + 'width' => $resize_dimensions['width'], + 'height' => $resize_dimensions['height'], + 'size' => floor(filesize($destination_filepath) / 1024).' KB', + 'time' => number_format((get_moment() - $starttime) * 1000, 2, '.', ' ').' ms', + 'library' => 'GD', + ); } function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false, $crop=false, $follow_orientation=true) { + $starttime = get_moment(); + // extension of the picture filename $extension = strtolower(get_extension($source_filepath)); if (!in_array($extension, array('jpg', 'jpeg', 'png'))) @@ -705,7 +716,15 @@ function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width $image->destroy(); // everything should be OK if we are here! - return true; + return array( + 'source' => $source_filepath, + 'destination' => $destination_filepath, + 'width' => $resize_dimensions['width'], + 'height' => $resize_dimensions['height'], + 'size' => floor(filesize($destination_filepath) / 1024).' KB', + 'time' => number_format((get_moment() - $starttime) * 1000, 2, '.', ' ').' ms', + 'library' => 'ImageMagick', + ); } function get_rotation_angle($source_filepath) 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) @@ -408,7 +408,8 @@ function ws_addDefaultMethods( $arr ) 'pwg.images.resize', 'ws_images_resize', array( - 'image_id' => array(), + 'image_id' => array('default' => null), + 'image_path' => array('default' => null), 'type' => array('default' => 'thumbnail'), 'maxwidth' => array('default' => null), 'maxheight' => array('default' => null), @@ -416,7 +417,8 @@ function ws_addDefaultMethods( $arr ) 'follow_orientation' => array('default' => null), 'quality' => array('default' => null), ), - 'Regenerate thumbnails or websize photo with given arguments. + '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.' ); |