Changeset 23125


Ignore:
Timestamp:
Jun 10, 2013, 3:50:22 PM (7 years ago)
Author:
plg
Message:

manage a min and a max ratio:

File:
1 edited

Legend:

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

    r23074 r23125  
    2626{
    2727  global $conf;
     28
     29  $asize_conf_default_values = array(
     30    'automatic_size_width_margin' => 12,
     31    'automatic_size_height_margin' => 40,
     32    'automatic_size_min_ratio' => 0.2,
     33    'automatic_size_max_ratio' => 5,
     34    );
     35
     36  foreach (array_keys($asize_conf_default_values) as $key)
     37  {
     38    if (!isset($conf[$key]))
     39    {
     40      $conf[$key] = $asize_conf_default_values[$key];
     41    }
     42  }
    2843
    2944  if ( !empty($content) )
     
    6681      if ($size)
    6782      {
    68         if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1])
     83        // if we have a very high picture (such as an infographic), we only try to match width
     84        if ($size[0]/$size[1] < $conf['automatic_size_min_ratio'])
    6985        {
    70           $automatic_size = $type;
     86          if ($size[0] <= $available_size[0])
     87          {
     88            $automatic_size = $type;
     89          }
     90        }
     91        // if we have a very wide picture (panoramic), we only try to match height
     92        elseif ($size[0]/$size[1] > $conf['automatic_size_max_ratio'])
     93        {
     94          if ($size[1] <= $available_size[1])
     95          {
     96            $automatic_size = $type;
     97          }
     98        }
     99        else
     100        {
     101          if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1])
     102          {
     103            $automatic_size = $type;
     104          }
    71105        }
    72106      }
     
    127161      'ALT_IMG' => $element_info['file'],
    128162      'COOKIE_PATH' => cookie_path(),
    129       'asize_width_margin' => isset($conf['automatic_size_width_margin']) ? $conf['automatic_size_width_margin'] : 12,
    130       'asize_height_margin' => isset($conf['automatic_size_height_margin']) ? $conf['automatic_size_height_margin'] : 40,
     163      'asize_width_margin' => $conf['automatic_size_width_margin'],
     164      'asize_height_margin' => $conf['automatic_size_height_margin'],
    131165      )
    132166    );
Note: See TracChangeset for help on using the changeset viewer.