addMethod('pwg.image.thumbcrop', 'ws_thumbcrop', array( 'image_id'=>array(), 'x1' => array(), 'y1' => array(), 'x2' => array(), 'y2' => array(), 'width' => array(), 'height' => array(), 'pwg_token' => array() ), 'Create a thumbnail with advanced options' ); function ws_thumbcrop($params, &$service) { if (!is_admin()) { return new PwgError(401, 'Access denied'); } if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) { return new PwgError(403, 'Invalid security token'); } foreach (array('x1','y1','x2','y2','width','height','image_id') as $p) { if (!isset($params[$p])) { return new PwgError(403, "$p is missing"); } } include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); $image_id=(int)$params['image_id']; $x1 = (int) $params['x1']; $x2 = (int) $params['x2']; $y1 = (int) $params['y1']; $y2 = (int) $params['y2']; $width = (int) $params['width']; $height = (int) $params['height']; $query=' SELECT id, path, tn_ext, has_high FROM '.IMAGES_TABLE.' WHERE id = '.$image_id.' ;'; $image = pwg_db_fetch_assoc(pwg_query($query)); if ($image == null) { return new PwgError(403, "image_id not found"); } $image_path = $image['path']; $thumb_path = get_thumbnail_path($image); $img = new pwg_image($image_path); $img->image->crop($x2-$x1,$y2-$y1,$x1,$y1); $img->image->resize($width,$height); $img->write($thumb_path); return true; } ?>