Changeset 13038


Ignore:
Timestamp:
Feb 6, 2012, 9:59:20 PM (13 years ago)
Author:
rvelices
Message:

multisize - added the coi (still to affine the admin ui + language)
multisize - derivatives can be revuild from a larger derviative instead of the original

Location:
trunk
Files:
7 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/picture_modify.php

    r13013 r13038  
    304304  );
    305305
     306if (in_array(get_extension($row['path']),$conf['picture_ext']))
     307{
     308  $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&image_id='.$_GET['image_id']);
     309}
     310
    306311// image level options
    307312$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
  • trunk/admin/themes/default/template/picture_modify.tpl

    r12855 r13038  
    8484      </tr>
    8585      {/if}
    86 
     86{if isset($U_COI)}
     87      <tr>
     88        <td></td>
     89        <td><a href="{$U_COI}">{'Not cropped correctly?'|@translate}</a></td>
     90      </tr>
     91{/if}
    8792    </table>
    8893
  • trunk/i.php

    r13021 r13038  
    233233  }
    234234  array_shift($deriv);
    235   $page['coi'] = '';
    236   if (count($deriv) && $deriv[0][0]=='c' && $deriv[0][1]=='i')
    237   {
    238     $page['coi'] = substr(array_shift($deriv), 2);
    239     preg_match('#^[a-zA-Z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
    240   }
    241235
    242236  if ($page['derivative_type'] == IMG_CUSTOM)
     
    257251      ierror('Too big', 403);
    258252    }
    259    
     253
    260254    $key = array();
    261255    $params->add_url_tokens($key);
     
    267261  }
    268262
    269   if (!is_file(PHPWG_ROOT_PATH.$req.$ext) and
    270       is_file(PHPWG_ROOT_PATH.'../'.$req.$ext) )
     263  if (is_file(PHPWG_ROOT_PATH.$req.$ext))
     264  {
     265    $req = './'.$req; // will be used to match #iamges.path
     266  }
     267  elseif (is_file(PHPWG_ROOT_PATH.'../'.$req.$ext))
     268  {
    271269    $req = '../'.$req;
     270  }
    272271
    273272  $page['src_location'] = $req.$ext;
     
    276275}
    277276
     277function try_switch_source(DerivativeParams $params, $original_mtime)
     278{
     279  global $page;
     280  $candidates = array();
     281  foreach(ImageStdParams::get_defined_type_map() as $candidate)
     282  {
     283    if ($candidate->type == $params->type)
     284      continue;
     285    if ($candidate->use_watermark != $params->use_watermark)
     286      continue;
     287    if ($candidate->max_width() < $params->max_width() || $candidate->max_height() < $params->max_height())
     288      continue;
     289    if ($params->sizing->max_crop==0)
     290    {
     291      if ($candidate->sizing->max_crop!=0)
     292        continue;
     293    }
     294    else
     295    {
     296      if ($candidate->sizing->max_crop!=0)
     297        continue; // this could be optimized
     298      if (!isset($page['original_size']))
     299        continue;
     300      $candidate_size = $candidate->compute_final_size($page['original_size']);
     301      if ($candidate_size[0] < $params->sizing->min_size[0] || $candidate_size[1] < $params->sizing->min_size[1] )
     302        continue;
     303    }
     304    $candidates[] = $candidate;
     305  }
     306
     307  foreach( array_reverse($candidates) as $candidate)
     308  {
     309    $candidate_path = $page['derivative_path'];
     310    $candidate_path = str_replace( '-'.derivative_to_url($params->type), '-'.derivative_to_url($candidate->type), $candidate_path);
     311    $candidate_mtime = @filemtime($candidate_path);
     312    if ($candidate_mtime === false
     313      || $candidate_mtime < $original_mtime
     314      || $candidate_mtime < $candidate->last_mod_time)
     315      continue;
     316    $params->use_watermark = false;
     317    $params->sharpen = min(1, $params->sharpen);
     318    $page['src_path'] = $candidate_path;
     319    $page['src_url'] = $page['root_path'] . substr($candidate_path, strlen(PHPWG_ROOT_PATH));
     320  }
     321}
    278322
    279323function send_derivative($expires)
     
    362406  send_derivative($expires);
    363407}
     408
     409$page['coi'] = null;
     410if (strpos($page['src_location'], '/pwg_representative/')===false
     411    && strpos($page['src_location'], 'themes/')===false
     412    && strpos($page['src_location'], 'plugins/')===false)
     413{
     414  @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'config/database.inc.php');
     415  include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php');
     416  try
     417  {
     418    $pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
     419                                  $conf['db_password'], $conf['db_base']);
     420    $query = 'SELECT coi, width, height FROM '.$prefixeTable.'images WHERE path=\''.$page['src_location'].'\'';
     421    if ( ($row=pwg_db_fetch_assoc(pwg_query($query))) )
     422    {
     423      if (isset($row['width']))
     424      {
     425        $page['original_size'] = array($row['width'],$row['height']);
     426      }
     427      $page['coi'] = $row['coi'];
     428    }
     429    mysql_close($pwg_db_link);
     430    if (!$row)
     431    {
     432      ierror('Db file path not found', 404);
     433    }
     434  }
     435  catch (Exception $e)
     436  {
     437    ilog("db error", $e->getMessage());
     438  }
     439}
     440
     441try_switch_source($params, $src_mtime);
    364442
    365443if (!mkgetdir(dirname($page['derivative_path'])))
  • trunk/include/dblayer/functions_mysql.inc.php

    r12922 r13038  
    8585  global $conf,$page,$debug,$t2;
    8686
    87   $start = get_moment();
     87  $start = microtime(true);
    8888  ($result = mysql_query($query)) or my_error($query, $conf['die_on_sql_error']);
    8989
    90   $time = get_moment() - $start;
     90  $time = microtime(true) - $start;
    9191
    9292  if (!isset($page['count_queries']))
     
    200200  while ($row = mysql_fetch_assoc($result))
    201201  {
    202     array_push($array, $row[$fieldname]);
     202    $array[] = $row[$fieldname];
    203203  }
    204204
  • trunk/include/derivative.inc.php

    r12954 r13038  
    2828  public $rel_path;
    2929
    30   public $coi=null;
    3130  private $size=null;
    3231  private $flags=0;
     
    3534  {
    3635    global $conf;
    37    
     36
    3837    $this->id = $infos['id'];
    3938    $ext = get_extension($infos['path']);
     
    5554    }
    5655
    57     $this->coi = @$infos['coi'];
    5856    if (!$this->size && isset($infos['width']) && isset($infos['height']))
    5957    {
     
    168166    $tokens=array();
    169167    $tokens[] = substr($params->type,0,2);
    170 
    171     if ($params->sizing->max_crop != 0 and !empty($src->coi))
    172     {
    173       $tokens[] = 'ci'.$src->coi;
    174     }
    175168
    176169    if ($params->type==IMG_CUSTOM)
     
    258251      return $this->src_image->get_size();
    259252    }
    260     return $this->params->compute_final_size($this->src_image->get_size(), $this->src_image->coi);
     253    return $this->params->compute_final_size($this->src_image->get_size());
    261254  }
    262255
  • trunk/include/derivative_params.inc.php

    r13035 r13038  
    4646function fraction_to_char($f)
    4747{
    48         return ord('a') + round($f*25);
     48        return chr(ord('a') + round($f*25));
    4949}
    5050
     
    258258  }
    259259
    260   function compute_final_size($in_size, $coi)
    261   {
    262     $this->sizing->compute( $in_size, $coi, $crop_rect, $scale_size );
     260  function compute_final_size($in_size)
     261  {
     262    $this->sizing->compute( $in_size, null, $crop_rect, $scale_size );
    263263    return $scale_size != null ? $scale_size : $in_size;
    264264  }
  • trunk/include/derivative_std_params.inc.php

    r13021 r13038  
    7373    return self::$all_type_map[$type];
    7474  }
    75  
     75
    7676  static function get_custom($w, $h, $crop=0, $minw=null, $minh=null)
    7777  {
     
    9999    global $conf;
    100100    $arr = @unserialize($conf['derivatives']);
    101     if (false!==$arr)
    102     {
    103       self::$type_map = $arr['d'];
    104       self::$watermark = @$arr['w'];
    105       if (!self::$watermark) self::$watermark = new WatermarkParams();
    106     }
    107     else
    108     {
    109       self::make_default();
    110     }
    111     self::build_maps();
    112   }
    113 
    114   static function load_from_file()
    115   {
    116     global $conf;
    117     $arr = @unserialize(@file_get_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat'));
    118101    if (false!==$arr)
    119102    {
     
    131114  }
    132115
     116  static function load_from_file()
     117  {
     118    global $conf;
     119    $arr = @unserialize(@file_get_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat'));
     120    if (false!==$arr)
     121    {
     122      self::$type_map = $arr['d'];
     123      self::$watermark = @$arr['w'];
     124      if (!self::$watermark) self::$watermark = new WatermarkParams();
     125      self::$custom = @$arr['c'];
     126      if (!self::$custom) self::$custom = array();
     127    }
     128    else
     129    {
     130      self::make_default();
     131    }
     132    self::build_maps();
     133  }
     134
    133135  static function set_watermark($watermark)
    134136  {
    135137    self::$watermark = $watermark;
    136138  }
    137  
     139
    138140  static function set_and_save($map)
    139141  {
     
    177179    }
    178180  }
    179  
     181
    180182  private static function build_maps()
    181183  {
  • trunk/install/piwigo_structure-mysql.sql

    r11992 r13038  
    186186  `width` smallint(9) unsigned default NULL,
    187187  `height` smallint(9) unsigned default NULL,
     188        `coi` char(4) default NULL COMMENT 'center of interest',
    188189  `representative_ext` varchar(4) default NULL,
    189190  `date_metadata_update` date default NULL,
Note: See TracChangeset for help on using the changeset viewer.