Changeset 10563


Ignore:
Timestamp:
04/22/11 13:34:57 (9 years ago)
Author:
patdenice
Message:

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_upload.inc.php

    r10552 r10563  
    557557  } 
    558558 
     559  $starttime = get_moment(); 
    559560  $gd_info = gd_info(); 
    560561 
     
    646647 
    647648  // everything should be OK if we are here! 
    648   return true; 
     649  return array( 
     650    'source'      => $source_filepath, 
     651    'destination' => $destination_filepath, 
     652    'width'       => $resize_dimensions['width'], 
     653    'height'      => $resize_dimensions['height'], 
     654    'size'        => floor(filesize($destination_filepath) / 1024).' KB', 
     655    'time'            => number_format((get_moment() - $starttime) * 1000, 2, '.', ' ').' ms', 
     656    'library'     => 'GD', 
     657  ); 
    649658} 
    650659 
    651660function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false, $crop=false, $follow_orientation=true) 
    652661{ 
     662  $starttime = get_moment(); 
     663 
    653664  // extension of the picture filename 
    654665  $extension = strtolower(get_extension($source_filepath)); 
     
    706717 
    707718  // everything should be OK if we are here! 
    708   return true; 
     719  return array( 
     720    'source'      => $source_filepath, 
     721    'destination' => $destination_filepath, 
     722    'width'       => $resize_dimensions['width'], 
     723    'height'      => $resize_dimensions['height'], 
     724    'size'        => floor(filesize($destination_filepath) / 1024).' KB', 
     725    'time'            => number_format((get_moment() - $starttime) * 1000, 2, '.', ' ').' ms', 
     726    'library'     => 'ImageMagick', 
     727  ); 
    709728} 
    710729 
  • 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 
  • trunk/ws.php

    r10553 r10563  
    409409    'ws_images_resize', 
    410410    array( 
    411       'image_id' => array(), 
     411      'image_id' => array('default' => null), 
     412      'image_path' => array('default' => null), 
    412413      'type' => array('default' => 'thumbnail'), 
    413414      'maxwidth' => array('default' => null), 
     
    417418      'quality' => array('default' => null), 
    418419    ), 
    419     'Regenerate thumbnails or websize photo with given arguments. 
     420    'Create/Regenerate thumbnails or websize photo with given arguments. 
     421<br>One of arguments "image_id" or "image_path" must be passed filled. 
    420422<br>Argument "type" can be "thumbnail" or "websize". Default is "thumbnail". 
    421423<br>If maxwidth, maxheight, crop, follow_orientation or quality are missing, default parameters of upload will be used.' 
Note: See TracChangeset for help on using the changeset viewer.