Ignore:
Timestamp:
Apr 22, 2011, 1:34:57 PM (14 years ago)
Author:
patdenice
Message:

feature:2274
pwg.images.resize method is able to create or regenerate image from image path.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r10553 r10563  
    26742674  }
    26752675
     2676  if (empty($params['image_id']) and empty($params['image_path']))
     2677  {
     2678    return new PwgError(403, "image_id or image_path is missing");
     2679  }
     2680
    26762681  $resize_params = array('maxwidth', 'maxheight', 'quality', 'crop', 'follow_orientation');
    26772682  $type = $params['type'] == 'thumbnail' ? 'thumb' : 'websize';
     
    26822687  }
    26832688
    2684   $query='
     2689  include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     2690  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
     2691
     2692  if (!empty($params['image_id']))
     2693  {
     2694    $query='
    26852695SELECT id, path, tn_ext, has_high
    2686 FROM '.IMAGES_TABLE.'
    2687 WHERE id = '.(int)$params['image_id'].'
     2696  FROM '.IMAGES_TABLE.'
     2697  WHERE id = '.(int)$params['image_id'].'
    26882698;';
    2689   $image = pwg_db_fetch_assoc(pwg_query($query));
    2690 
    2691   if ($image == null)
    2692   {
    2693     return new PwgError(403, "image_id not found");
    2694   }
    2695 
    2696   include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    2697 
    2698   if (!is_valid_image_extension(get_extension($image['path'])))
     2699    $image = pwg_db_fetch_assoc(pwg_query($query));
     2700
     2701    if ($image == null)
     2702    {
     2703      return new PwgError(403, "image_id not found");
     2704    }
     2705
     2706    $image_path = $image['path'];
     2707    $thumb_path = get_thumbnail_path($image);
     2708    $hd_path = get_high_path($image);
     2709  }
     2710  else
     2711  {
     2712    $image_path = $params['image_path'];
     2713    $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)))
    26992718  {
    27002719    return new PwgError(403, "image can't be resized");
    27012720  }
    27022721
    2703   if ($params['type'] == 'thumbnail' and !empty($image['tn_ext']))
    2704   {
    2705     trigger_event(
     2722  $result = false;
     2723
     2724  if ($params['type'] == 'thumbnail' and file_exists($image_path))
     2725  {
     2726    prepare_directory(dirname($thumb_path));
     2727
     2728    $result = trigger_event(
    27062729      'upload_thumbnail_resize',
    27072730      false,
    2708       $image['path'],
    2709       get_thumbnail_path($image),
     2731      $image_path,
     2732      $thumb_path,
    27102733      $params['maxwidth'],
    27112734      $params['maxheight'],
     
    27152738      get_boolean($params['follow_orientation'])
    27162739    );
    2717     return true;
    2718   }
    2719   elseif (!empty($image['has_high']))
    2720   {
    2721     trigger_event(
     2740  }
     2741  elseif (file_exists($hd_path))
     2742  {
     2743    $result = trigger_event(
    27222744      'upload_image_resize',
    27232745      false,
    2724       file_path_for_type($image['path'], 'high'),
    2725       $image['path'],
     2746      $hd_path,
     2747      $image_path,
    27262748      $params['maxwidth'],
    27272749      $params['maxheight'],
     
    27302752      );
    27312753
    2732     $conf['use_exif'] = false;
    2733     $conf['use_iptc'] = false;
    2734     update_metadata(array($image['id'] => $image['path']));
    2735 
    2736     return true;
    2737   }
    2738   return false;
     2754    if (!empty($image['has_high']))
     2755    {
     2756      $conf['use_exif'] = false;
     2757      $conf['use_iptc'] = false;
     2758      update_metadata(array($image['id'] => $image['path']));
     2759    }
     2760  }
     2761  return $result;
    27392762}
    27402763
Note: See TracChangeset for help on using the changeset viewer.