Changeset 10686


Ignore:
Timestamp:
Apr 29, 2011, 7:38:59 PM (9 years ago)
Author:
patdenice
Message:

feature:2259
Create two different methods in webservice to create/regenerate thumbnail and to regenerate websize.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/image.class.php

    r10684 r10686  
    291291    if (is_null($library))
    292292    {
    293       $library = $conf['image_library'];
     293      $library = $conf['graphics_library'];
    294294    }
    295295
  • trunk/admin/themes/default/template/batch_manager_global.tpl

    r10637 r10686  
    334334    else if (jQuery('[name="selectAction"]').val() == 'regenerateThumbnails')
    335335    {
    336       type = 'thumbnail';
     336      resizeMethod = 'pwg.images.resizeThumbnail';
    337337      maxRequests = 3;
    338338      maxwidth = jQuery('input[name="thumb_maxwidth"]').val();
     
    344344    else if(jQuery('[name="selectAction"]').val() == 'regenerateWebsize')
    345345    {
    346       type = 'websize';
     346      resizeMethod = 'pwg.images.resizeWebsize';
    347347      maxRequests = 1;
    348348      maxwidth = jQuery('input[name="websize_maxwidth"]').val();
     
    391391        url: 'ws.php',
    392392        data: {
    393           method: 'pwg.images.resize',
    394           type: type,
     393          method: resizeMethod,
    395394          maxwidth: maxwidth,
    396395          maxheight: maxheight,
  • trunk/admin/themes/default/template/thumbnail.tpl

    r10571 r10686  
    3131      url: 'ws.php',
    3232      data: {
    33         method: 'pwg.images.resize',
     33        method: 'pwg.images.resizeThumbnail',
    3434        image_path: image_path,
    35         type: 'thumbnail',
    3635        maxwidth: width,
    3736        maxheight: height,
  • trunk/include/ws_functions.inc.php

    r10653 r10686  
    26592659}
    26602660
    2661 function ws_images_resize($params, &$service)
    2662 {
    2663   global $conf;
    2664 
     2661function ws_images_resizethumbnail($params, &$service)
     2662{
    26652663  if (!is_admin())
    26662664  {
     
    26682666  }
    26692667
    2670   if (!in_array($params['type'], array('thumbnail', 'websize')))
    2671   {
    2672     return new PwgError(403, 'Unknown type (only "thumbnail" or "websize" are accepted');
    2673   }
    2674 
    26752668  if (empty($params['image_id']) and empty($params['image_path']))
    26762669  {
     
    26782671  }
    26792672
    2680   $resize_params = array('maxwidth', 'maxheight', 'quality', 'crop', 'follow_orientation');
    2681   $type = $params['type'] == 'thumbnail' ? 'thumb' : 'websize';
    2682   foreach ($resize_params as $param)
    2683   {
    2684     if (empty($params[$param]) and isset($conf['upload_form_'.$type.'_'.$param]))
    2685       $params[$param] = $conf['upload_form_'.$type.'_'.$param];
    2686   }
    2687 
    2688   include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    26892673  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    26902674  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
     
    27062690    $image_path = $image['path'];
    27072691    $thumb_path = get_thumbnail_path($image);
    2708     $hd_path = get_high_path($image);
    27092692  }
    27102693  else
     
    27122695    $image_path = $params['image_path'];
    27132696    $thumb_path = file_path_for_type($image_path, 'thumb');
    2714     $hd_path = file_path_for_type($image_path, 'high');
    2715   }
    2716 
    2717   if (!is_valid_image_extension(get_extension($image_path)))
     2697  }
     2698
     2699  if (!file_exists($image_path) or !is_valid_image_extension(get_extension($image_path)))
    27182700  {
    27192701    return new PwgError(403, "image can't be resized");
     
    27212703
    27222704  $result = false;
    2723 
    2724   if ($params['type'] == 'thumbnail' and file_exists($image_path))
    2725   {
    2726     prepare_directory(dirname($thumb_path));
    2727 
    2728     $img = new pwg_image($image_path, $params['library']);
    2729 
    2730     $result =  $img->pwg_resize(
    2731       $thumb_path,
    2732       $params['maxwidth'],
    2733       $params['maxheight'],
    2734       $params['quality'],
    2735       $params['automatic_rotation'],
    2736       true,
    2737       get_boolean($params['crop']),
    2738       get_boolean($params['follow_orientation'])
    2739     );
    2740 
    2741     $img->destroy();
    2742   }
    2743   elseif (file_exists($hd_path))
    2744   {
    2745     $img = new pwg_image($hd_path);
    2746 
    2747     $result = $img->pwg_resize(
    2748       $image_path,
    2749       $params['maxwidth'],
    2750       $params['maxheight'],
    2751       $params['quality'],
    2752       $params['automatic_rotation'],
    2753       false
    2754       );
    2755 
    2756     $img->destroy();
    2757 
    2758     if (!empty($image['has_high']))
    2759     {
    2760       $conf['use_exif'] = false;
    2761       $conf['use_iptc'] = false;
    2762       update_metadata(array($image['id'] => $image['path']));
    2763     }
    2764   }
     2705  prepare_directory(dirname($thumb_path));
     2706  $img = new pwg_image($image_path, $params['library']);
     2707
     2708  $result =  $img->pwg_resize(
     2709    $thumb_path,
     2710    $params['maxwidth'],
     2711    $params['maxheight'],
     2712    $params['quality'],
     2713    false, // automatic rotation is not needed for thumbnails.
     2714    true, // strip metadata
     2715    get_boolean($params['crop']),
     2716    get_boolean($params['follow_orientation'])
     2717  );
     2718
     2719  $img->destroy();
     2720  return $result;
     2721}
     2722
     2723function ws_images_resizewebsize($params, &$service)
     2724{
     2725  if (!is_admin())
     2726  {
     2727    return new PwgError(401, 'Access denied');
     2728  }
     2729
     2730  include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     2731  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
     2732  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
     2733
     2734  $query='
     2735SELECT id, path, tn_ext, has_high
     2736  FROM '.IMAGES_TABLE.'
     2737  WHERE id = '.(int)$params['image_id'].'
     2738;';
     2739  $image = pwg_db_fetch_assoc(pwg_query($query));
     2740
     2741  if ($image == null)
     2742  {
     2743    return new PwgError(403, "image_id not found");
     2744  }
     2745
     2746  $image_path = $image['path'];
     2747  $hd_path = get_high_path($image);
     2748
     2749  if (empty($image['has_high']) or !file_exists($hd_path) or !is_valid_image_extension(get_extension($image_path)))
     2750  {
     2751    return new PwgError(403, "image can't be resized");
     2752  }
     2753
     2754  $result = false;
     2755  $img = new pwg_image($hd_path);
     2756
     2757  $result = $img->pwg_resize(
     2758    $image_path,
     2759    $params['maxwidth'],
     2760    $params['maxheight'],
     2761    $params['quality'],
     2762    $params['automatic_rotation'],
     2763    false // strip metadata
     2764    );
     2765
     2766  $img->destroy();
     2767
     2768  global $conf;
     2769  $conf['use_exif'] = false;
     2770  $conf['use_iptc'] = false;
     2771  update_metadata(array($image['id'] => $image['path']));
     2772
    27652773  return $result;
    27662774}
  • trunk/ws.php

    r10684 r10686  
    406406
    407407  $service->addMethod(
    408     'pwg.images.resize',
    409     'ws_images_resize',
     408    'pwg.images.resizeThumbnail',
     409    'ws_images_resizethumbnail',
    410410    array(
    411411      'image_id' => array('default' => null),
    412412      'image_path' => array('default' => null),
    413       'type' => array('default' => 'thumbnail'),
     413      'maxwidth' => array('default' => $conf['upload_form_thumb_maxwidth']),
     414      'maxheight' => array('default' => $conf['upload_form_thumb_maxheight']),
     415      'quality' => array('default' => $conf['upload_form_thumb_quality']),
     416      'crop' => array('default' => $conf['upload_form_thumb_crop']),
     417      'follow_orientation' => array('default' => $conf['upload_form_thumb_follow_orientation']),
     418      'library' => array('default' => $conf['graphics_library']),
     419    ),
     420    'Create/Regenerate thumbnails photo with given arguments.
     421<br>One of arguments "image_id" or "image_path" must be sent.'
     422  );
     423
     424  $service->addMethod(
     425    'pwg.images.resizeWebsize',
     426    'ws_images_resizewebsize',
     427    array(
     428      'image_id' => array(),
     429      'maxwidth' => array('default' => $conf['upload_form_websize_maxwidth']),
     430      'maxheight' => array('default' => $conf['upload_form_websize_maxheight']),
     431      'quality' => array('default' => $conf['upload_form_websize_quality']),
    414432      'automatic_rotation' => array('default' => $conf['upload_form_automatic_rotation']),
    415433      'library' => array('default' => $conf['graphics_library']),
    416       'maxwidth' => array('default' => null),
    417       'maxheight' => array('default' => null),
    418       'crop' => array('default' => null),
    419       'follow_orientation' => array('default' => null),
    420       'quality' => array('default' => null),
    421434    ),
    422     'Create/Regenerate thumbnails or websize photo with given arguments.
    423 <br>One of arguments "image_id" or "image_path" must be passed filled.
    424 <br>Argument "type" can be "thumbnail" or "websize". Default is "thumbnail".
    425 <br>If maxwidth, maxheight, crop, follow_orientation or quality are missing, default parameters of upload will be used.'
    426 );
     435    'Regenerate websize photo with given arguments.'
     436  );
    427437
    428438  $service->addMethod(
Note: See TracChangeset for help on using the changeset viewer.