Ignore:
Timestamp:
Dec 28, 2013, 6:08:42 PM (10 years ago)
Author:
mistic100
Message:

update for 2.6 + better calculation + option to force ratio
TODO: issue with PNG (unable to generate thumbnail with IM)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/header_manager/include/functions.inc.php

    r22857 r26298  
    88function list_banners($delete_orphans=false)
    99{
    10   if (!file_exists(HEADER_MANAGER_DIR)) return array();
     10  if (!file_exists(HEADER_MANAGER_DIR))
     11  {
     12    return array();
     13  }
     14 
    1115  $dir = scandir(HEADER_MANAGER_DIR);
    1216  $banners = array();
     
    1418  foreach ($dir as $file)
    1519  {
    16     if ( in_array($file, array('.','..','index.php','.svn')) ) continue;
    17     if ( !in_array(strtolower(get_extension($file)), array('jpg','jpeg','png','gif')) ) continue;
    18     if ( strpos($file, '-thumbnail')!==false ) continue;
     20    if (in_array($file, array('.','..','index.php','.svn'))) continue;
     21    if (!in_array(strtolower(get_extension($file)), array('jpg','jpeg','png','gif'))) continue;
     22    if (strpos($file, '-thumbnail')!==false) continue;
    1923   
    2024    $banner = get_banner($file);
    2125
    22     if ( $delete_orphans and !file_exists($banner['THUMB']) )
     26    if ($delete_orphans and !file_exists($banner['THUMB']))
    2327    {
    2428      @unlink($banner['PATH']);
     
    4347    return array(
    4448      'NAME' => $file,
    45       'PATH' => get_root_url().HEADER_MANAGER_DIR . $file,
    46       'THUMB' => get_root_url().HEADER_MANAGER_DIR . get_filename_wo_extension($file) . '-thumbnail.'. get_extension($file),
     49      'PATH' => get_root_url() . HEADER_MANAGER_DIR . $file,
     50      'THUMB' => get_root_url() . HEADER_MANAGER_DIR . get_filename_wo_extension($file) . '-thumbnail.' . get_extension($file),
    4751      'SIZE' => getimagesize(HEADER_MANAGER_DIR . $file),
    4852      );
     
    8589  $crop['coi']['y'] = ($picture['coi']['b']+$picture['coi']['t'])/2;
    8690 
    87   // define default crop frame
    88   if ($picture['width'] > $conf['header_manager']['width'])
     91  $crop['desired_width'] = $conf['header_manager']['width'];
     92  $crop['desired_height'] = $conf['header_manager']['height'];
     93 
     94  if ($picture['width'] > $crop['desired_width'])
    8995  {
    90     $crop['display_width'] = $conf['header_manager']['width'];
    91     $crop['display_height'] = round($picture['height']*$crop['display_width']/$picture['width']);
    92    
    93     $crop['coi']['x'] = round($crop['coi']['x']*$crop['display_width']/$picture['width']);
    94     $crop['coi']['y'] = round($crop['coi']['y']*$crop['display_height']/$picture['height']);
    95    
    96     $crop['l'] = 0;
    97     $crop['r'] = $conf['header_manager']['width'];
    98     $crop['t'] = max(0, $crop['coi']['y']-$conf['header_manager']['height']/2);
    99     $crop['b'] = min($crop['display_height'], $crop['t']+$conf['header_manager']['height']);
     96    $crop['box_width'] = $crop['desired_width'];
     97    $crop['box_height'] = round($picture['height']*$crop['box_width']/$picture['width']);
    10098  }
    10199  else
    102100  {
    103     $crop['display_width'] = $picture['width'];
    104     $crop['display_height'] = $picture['height'];
    105    
    106     $adapted_crop_height = round($conf['header_manager']['height']*$picture['width']/$conf['header_manager']['width']);
    107    
    108     $crop['l'] = 0;
    109     $crop['r'] = $picture['width'];
    110     $crop['t'] = max(0, $crop['coi']['y']-$adapted_crop_height/2);
    111     $crop['b'] = min($crop['display_height'], $crop['t']+$adapted_crop_height);
     101    $crop['box_width'] = $picture['width'];
     102    $crop['box_height'] = $picture['height'];
    112103  }
     104 
     105  $crop['real_width'] = $picture['width'];
     106  $crop['real_height'] = round($crop['desired_height']*$crop['real_width']/$crop['desired_width']);
     107 
     108  $crop['l'] = 0;
     109  $crop['r'] = $crop['real_width'];
     110  $crop['t'] = max(0, $crop['coi']['y']-$crop['real_height']/2);
     111  $crop['b'] = min($picture['height'], $crop['t']+$crop['real_height']);
    113112 
    114113  return $crop;
    115114}
    116 
    117 /**
    118  * clean table when categroies are delete
    119  */
    120 function header_manager_delete_categories($ids)
    121 {
    122   $query = '
    123 DELETE FROM '.HEADER_MANAGER_TABLE.'
    124   WHERE category_id IN('.implode(',', $ids).')
    125 ;';
    126   pwg_query($query);
    127 }
    128 
    129 ?>
Note: See TracChangeset for help on using the changeset viewer.