Ignore:
Timestamp:
03/20/12 23:32:30 (8 years ago)
Author:
patdenice
Message:

Compatible with Piwigo 2.4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/GThumb/main.inc.php

    r12924 r13652  
    1414 
    1515define('GTHUMB_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); 
    16 define('GTHUMB_CACHE_DIR', PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb'); 
    1716 
    1817$conf['GThumb'] = unserialize($conf['GThumb']); 
     
    2625 
    2726add_event_handler('loc_begin_index', 'GThumb_init', 60); 
    28 add_event_handler('ws_add_methods', 'add_gthumb_thumbnails_method'); 
    2927add_event_handler('get_admin_plugin_menu_links', 'GThumb_admin_menu'); 
    3028 
     
    4846  $template->assign('GThumb', $conf['GThumb']); 
    4947 
    50   include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); 
     48  $template->assign('GThumb_derivative_params', ImageStdParams::get_custom(9999, $conf['GThumb']['height'])); 
    5149 
    52   foreach ($tpl_vars as $key => &$tpl_var) 
     50  if ($conf['GThumb']['big_thumb'] and !empty($tpl_vars[0])) 
    5351  { 
    54     $data = get_gthumb_data($pictures[$key]); 
    55  
    56     $tpl_var['TN_SRC'] = $data['src']; 
    57     $tpl_var['TN_WIDTH'] = $data['width']; 
    58     $tpl_var['TN_HEIGHT'] = $data['height']; 
     52    $derivative_params = ImageStdParams::get_custom(9999, 2 * $conf['GThumb']['height'] + $conf['GThumb']['margin']); 
     53    $template->assign('GThumb_big', new DerivativeImage($derivative_params, $tpl_vars[0]['src_image'])); 
    5954  } 
    6055 
    61   if ($conf['GThumb']['big_thumb']) 
    62   { 
    63     $ft = &$tpl_vars[0]; 
    64  
    65     // Small thumb data 
    66     $small_thumb = array( 
    67       'id' => $ft['ID'], 
    68       'src' => $ft['TN_SRC'], 
    69       'width' => $ft['TN_WIDTH'], 
    70       'height' => $ft['TN_HEIGHT'], 
    71     ); 
    72  
    73     if (empty($small_thumb['src'])) 
    74     { 
    75       include_once(GTHUMB_PATH.'functions.inc.php'); 
    76       $data = get_gthumb_data($pictures[0]); 
    77       $result = make_gthumb_image($pictures[0], $data); 
    78       $small_thumb['src'] = $result['destination']; 
    79     } 
    80  
    81     // Big thumb data 
    82     $data = get_gthumb_data($pictures[0], 'big'); 
    83  
    84     $big_thumb = array( 
    85       'id' => $ft['ID'], 
    86       'src' => $data['src'], 
    87       'width' => $data['width'], 
    88       'height' => $data['height'], 
    89     ); 
    90     if (empty($big_thumb['src'])) 
    91     { 
    92       if ($conf['GThumb']['cache_big_thumb']) 
    93       { 
    94         include_once(GTHUMB_PATH.'functions.inc.php'); 
    95         $result = make_gthumb_image($pictures[0], $data); 
    96         $big_thumb['src'] = embellish_url(get_root_url().$result['destination']); 
    97       } 
    98       else 
    99       { 
    100         $big_thumb['src'] = get_root_url().'ws.php?method=pwg.images.getGThumbPlusThumbnail&image_id='.$ft['ID'].'&size=big&return=true'; 
    101       } 
    102     } 
    103  
    104     $template->assign( 
    105       array( 
    106         'small_thumb' => $small_thumb, 
    107         'big_thumb' => $big_thumb, 
    108       ) 
    109     ); 
    110     $ft['TN_SRC'] = $big_thumb['src']; 
    111     $ft['TN_WIDTH'] = $big_thumb['width']; 
    112     $ft['TN_HEIGHT'] = $big_thumb['height']; 
    113   } 
    114    
    11556  return $tpl_vars; 
    116 } 
    117  
    118 function add_gthumb_thumbnails_method($arr) 
    119 { 
    120   include_once(GTHUMB_PATH.'functions.inc.php'); 
    121  
    122   $service = &$arr[0]; 
    123   $service->addMethod( 
    124     'pwg.images.getGThumbPlusThumbnail', 
    125     'ws_images_getGThumbPlusThumbnail', 
    126     array( 
    127       'image_id' => array(), 
    128       'size' => array('default'=>'small'), 
    129       'return' => array('default'=>false), 
    130     ), 
    131     'Get thumbnail for GThumb+ plugin. Size parameter can be "small" or "big".' 
    132   ); 
    133 } 
    134  
    135 function get_gthumb_data($picture, $size='small') 
    136 { 
    137   global $conf; 
    138  
    139   $picture_ext = array('jpg', 'jpeg', 'png', 'gif'); 
    140  
    141   if (!in_array(strtolower(get_extension($picture['path'])), $picture_ext)) 
    142   { 
    143     list($width, $height) = getimagesize(get_thumbnail_path($picture)); 
    144  
    145     return array( 
    146       'src' => get_thumbnail_url($picture), 
    147       'width' => $width, 
    148       'height' => $height, 
    149     ); 
    150   } 
    151  
    152   $new_height = $size == 'small' ? $conf['GThumb']['height'] : $conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']; 
    153   $file = GTHUMB_CACHE_DIR.'/'.$new_height.'/'.md5($picture['path'].(!empty($picture['md5sum']) ? $picture['md5sum'] : '')).'.'.$picture['tn_ext']; 
    154  
    155   if (file_exists($file)) 
    156   { 
    157     list($width, $height) = getimagesize($file); 
    158  
    159     return array( 
    160       'src' => embellish_url(get_root_url().$file), 
    161       'width' => $width, 
    162       'height' => $height, 
    163     ); 
    164   } 
    165  
    166   if ( !empty($picture['tn_ext']) ) 
    167   { 
    168     $file = substr_replace(get_filename_wo_extension($picture['path']), '/thumbnail/GT-',strrpos($picture['path'],'/'),1).'.'.$picture['tn_ext']; 
    169     if (file_exists($file)) 
    170     { 
    171       list($width, $height) = getimagesize($file); 
    172  
    173       return array( 
    174         'src' => embellish_url(get_root_url().$file), 
    175         'width' => $width, 
    176         'height' => $height, 
    177       ); 
    178     } 
    179   } 
    180  
    181   $width = $picture['width']; 
    182   $height = $picture['height']; 
    183   $use_high = false; 
    184  
    185   if ($height < $new_height and $picture['has_high'] == 'true') 
    186   { 
    187     $width = $picture['high_width']; 
    188     $height = $picture['high_height']; 
    189     $use_high = true; 
    190   } 
    191  
    192   if ($size == 'big') 
    193   { 
    194     $width = min($width, round(max($height, $new_height) * 1.15)); 
    195   } 
    196  
    197   $result = pwg_image::get_resize_dimensions($width, $height, 5000, $new_height); 
    198   $result['src'] = ''; 
    199  
    200   // Test thumbnail size 
    201   list($width, $height) = getimagesize(get_thumbnail_path($picture)); 
    202   if ($result['width'] == $width and $result['height'] == $height) 
    203   { 
    204     $result['src'] = get_thumbnail_url($picture); 
    205   } 
    206  
    207   $result['use_high'] = $use_high; 
    208   $result['cache_path'] = GTHUMB_CACHE_DIR.'/'.$new_height.'/'; 
    209   $result['size'] = $size; 
    210  
    211   return $result; 
    21257} 
    21358 
Note: See TracChangeset for help on using the changeset viewer.