Changeset 12908


Ignore:
Timestamp:
Jan 17, 2012, 7:09:32 AM (12 years ago)
Author:
rvelices
Message:

feature 2548 multisize - ability to choose displayed size on index page
-added some logs on i.php (configurable) to measure the perf

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/i.php

    r12865 r12908  
    2929defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
    3030
     31function get_moment()
     32{
     33  $t1 = explode( ' ', microtime() );
     34  $t2 = explode( '.', $t1[0] );
     35  $t2 = $t1[1].'.'.$t2[1];
     36  return $t2;
     37}
    3138function trigger_action() {}
    3239function get_extension( $filename )
     
    6471// end fast bootstrap
    6572
     73function ilog()
     74{
     75  global $conf, $ilogfh;
     76  if (!$conf['enable_i_log']) return;
     77  if(!$ilogfh)
     78  {
     79    $dir=PHPWG_ROOT_PATH.$conf['data_location'].'tmp/';
     80    if (!mkgetdir($dir) or ! ($ilogfh=fopen($dir.'i.log', 'a')) )
     81      return;
     82  }
     83  fwrite($ilogfh, date("c") );
     84  foreach( func_get_args() as $arg)
     85  {
     86    fwrite($ilogfh, ' ' );
     87    if (is_array($arg))
     88    {
     89      fwrite($ilogfh, implode(' ', $arg) );
     90    }
     91    else
     92    {
     93      fwrite($ilogfh, $arg);
     94    }
     95  }
     96  fwrite($ilogfh, "\n");
     97}
    6698
    6799function ierror($msg, $code)
     
    93125}
    94126
     127function time_step( &$step )
     128{
     129  $tmp = $step;
     130  $step = get_moment();
     131  return intval(1000*($step - $tmp));
     132}
    95133
    96134function parse_request()
     
    160198  }
    161199  array_shift($deriv);
    162 
    163200  $page['coi'] = '';
    164201  if (count($deriv) && $deriv[0][0]=='c' && $deriv[0][1]=='i')
    165202  {
    166203    $page['coi'] = substr(array_shift($deriv), 2);
    167     preg_match('#^[a-z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
     204    preg_match('#^[a-zA-Z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
    168205  }
    169206
     
    188225  }
    189226
    190   if ($req[0]!='g' && $req[0]!='u')
     227  if (!is_file(PHPWG_ROOT_PATH.$req.$ext) and
     228      is_file(PHPWG_ROOT_PATH.'../'.$req.$ext) )
    191229    $req = '../'.$req;
    192230
     
    226264
    227265$page=array();
     266$begin = $step = get_moment();
     267$timing=array();
     268foreach( explode(',','load,rotate,crop,scale,sharpen,watermark,save,send') as $k )
     269{
     270  $timing[$k] = '';
     271}
    228272
    229273include_once( PHPWG_ROOT_PATH .'/include/derivative_params.inc.php');
     
    288332
    289333$image = new pwg_image($page['src_path']);
     334$timing['load'] = time_step($step);
    290335
    291336$changes = 0;
     
    300345  $changes++;
    301346  $image->crop( $crop_rect->width(), $crop_rect->height(), $crop_rect->l, $crop_rect->t);
     347  $timing['crop'] = time_step($step);
    302348}
    303349
     
    307353  $image->resize( $scaled_size[0], $scaled_size[1] );
    308354  $d_size = $scaled_size;
     355  $timing['scale'] = time_step($step);
    309356}
    310357
     
    312359{
    313360  $changes += $image->sharpen( $params->sharpen );
     361  $timing['sharpen'] = time_step($step);
    314362}
    315363
     
    346394  }
    347395  $wm_image->destroy();
     396  $timing['watermark'] = time_step($step);
    348397}
    349398
     
    358407$image->write( $page['derivative_path'] );
    359408$image->destroy();
     409$timing['save'] = time_step($step);
    360410
    361411send_derivative($expires);
     412$timing['send'] = time_step($step);
     413
     414ilog('perf',
     415  basename($page['src_path']), $o_size, $o_size[0]*$o_size[1],
     416  basename($page['derivative_path']), $d_size, $d_size[0]*$d_size[1],
     417  time_step($begin),
     418  $timing);
    362419?>
  • trunk/include/category_default.inc.php

    r12887 r12908  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    105105      );
    106106
    107   if (isset($nb_comments_of) )
     107  if (isset($nb_comments_of))
    108108  {
    109     $row['nb_comments'] = (int)@$nb_comments_of[$row['id']];
     109    $row['NB_COMMENTS'] = $row['nb_comments'] = (int)@$nb_comments_of[$row['id']];
    110110  }
    111111
    112112  $name = get_picture_title($row);
    113113
    114   $tpl_var = array(
    115     'ID' => $row['id'],
     114  $tpl_var = array_merge( $row, array(
    116115    'TN_SRC' => DerivativeImage::thumb_url($row),
    117116    'TN_ALT' => htmlspecialchars(strip_tags($name)),
    118117    'TN_TITLE' => get_thumbnail_title($row),
    119118    'URL' => $url,
     119    'src_image' => new SrcImage($row),
     120    ) );
    120121
    121     // Extra fields for usage in extra themes
    122     'FILE_PATH' => $row['path'],
    123     'FILE_POSTED' => $row['date_available'],
    124     'FILE_CREATED' => $row['date_creation'],
    125     'FILE_DESC' => $row['comment'],
    126     'FILE_AUTHOR' => $row['author'],
    127     'FILE_HIT' => $row['hit'],
    128     'FILE_SIZE' => $row['filesize'],
    129     'FILE_WIDTH' => $row['width'],
    130     'FILE_HEIGHT' => $row['height'],
    131     'FILE_METADATE' => $row['date_metadata_update'],
    132     'FILE_HAS_HD' => $row['has_high'],
    133     'FILE_HD_WIDTH' => $row['high_width'],
    134     'FILE_HD_HEIGHT' => $row['high_height'],
    135     'FILE_HD_FILESIZE' => $row['high_filesize'],
    136     'FILE_RATING_SCORE' => $row['rating_score'],
    137     );
    138  
    139122  if ($conf['index_new_icon'])
    140123  {
     
    146129    $tpl_var['NB_HITS'] = $row['hit'];
    147130  }
    148  
     131
    149132  switch ($page['section'])
    150133  {
     
    163146    }
    164147  }
    165  
     148
    166149  $tpl_var['NAME'] = $name;
    167 
    168   if (isset($row['nb_comments']))
    169   {
    170     $tpl_var['NB_COMMENTS'] = $row['nb_comments'];
    171   }
    172 
    173150  $tpl_thumbnails_var[] = $tpl_var;
    174151}
    175152
    176 $template->assign('SHOW_THUMBNAIL_CAPTION', $conf['show_thumbnail_caption']);
     153$derivative_params = ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) );
     154
     155$template->assign( array(
     156  'derivative_params' =>$derivative_params,
     157  'SHOW_THUMBNAIL_CAPTION' =>$conf['show_thumbnail_caption'],
     158    ) );
    177159$tpl_thumbnails_var = trigger_event('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
    178160$template->assign('thumbnails', $tpl_thumbnails_var);
    179161
    180162$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
    181 
     163unset($pictures, $selection, $tpl_thumbnails_var);
     164$template->clear_assign( array('thumbnails') );
    182165pwg_debug('end include/category_default.inc.php');
    183166?>
  • trunk/include/config_default.inc.php

    r12802 r12908  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    467467// gives an empty value '' to deactivate
    468468$conf['show_php_errors'] = E_ALL;
     469
     470// enable log for i derivative script
     471$conf['enable_i_log'] = false;
    469472
    470473// +-----------------------------------------------------------------------+
  • trunk/include/derivative.inc.php

    r12865 r12908  
    101101  public $src_image;
    102102
    103   private $requested_type;
    104 
    105103  private $flags = 0;
    106104  private $params;
     
    112110    if (is_string($type))
    113111    {
    114       $this->requested_type = $type;
    115112      $this->params = ImageStdParams::get_by_type($type);
    116113    }
    117114    else
    118115    {
    119       $this->requested_type = IMG_CUSTOM;
    120116      $this->params = $type;
    121117    }
     
    126122  static function thumb_url($infos)
    127123  {
    128     $src_image = new SrcImage($infos);
    129     self::build($src_image, ImageStdParams::get_by_type(IMG_THUMB), $rel_path, $rel_url);
    130     return get_root_url().$rel_url;
     124    return self::url(IMG_THUMB, $infos);
    131125  }
    132126
    133127  static function url($type, $infos)
    134128  {
    135     $src_image = new SrcImage($infos);
     129    $src_image = is_object($infos) ? $infos : new SrcImage($infos);
    136130    $params = is_string($type) ? ImageStdParams::get_by_type($type) : $type;
    137131    self::build($src_image, $params, $rel_path, $rel_url);
     
    258252    if ($size)
    259253    {
    260       return 'width="'.$size[0].'" height="'.$size[1].'"';
     254      return 'width='.$size[0].' height='.$size[1];
    261255    }
    262256  }
  • trunk/include/derivative_params.inc.php

    r12881 r12908  
    316316  }
    317317
     318  function max_width()
     319  {
     320    return $this->sizing->ideal_size[0];
     321  }
     322
     323  function max_height()
     324  {
     325    return $this->sizing->ideal_size[1];
     326  }
     327 
    318328  function is_identity($in_size)
    319329  {
  • trunk/include/template.class.php

    r12874 r12908  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    843843    return call_user_func_array('sprintf',  $args );
    844844  }
     845 
     846  function derivative_url($type, $img)
     847  {
     848    return DerivativeImage::url($type, $img);
     849  }
    845850}
    846851
  • trunk/index.php

    r12553 r12908  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    6161    );
    6262}
     63if (isset($_GET['display']))
     64{
     65  $page['meta_robots']['noindex']=1;
     66  if (array_key_exists($_GET['display'], ImageStdParams::get_defined_type_map()))
     67  {
     68    pwg_set_session_var('index_deriv', $_GET['display']);
     69  }
     70}
    6371//-------------------------------------------------------------- initialization
    6472
     
    253261}
    254262
     263if ( count($page['items']) > 0 )
     264{
     265  $url = add_url_params(
     266          duplicate_index_url(),
     267          array('display' => '')
     268        );
     269  $selected_type = pwg_get_session_var('index_deriv', IMG_THUMB);
     270  $type_map = ImageStdParams::get_defined_type_map();
     271  unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]);
     272  foreach($type_map as $params)
     273  {
     274    $template->append(
     275      'image_derivatives',
     276      array(
     277        'DISPLAY' => l10n($params->type),
     278        'URL' => $url.$params->type,
     279        'SELECTED' => ($params->type == $selected_type ? true:false),
     280        )
     281      );
     282  }
     283}
     284
    255285// category comment
    256286if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
  • trunk/themes/default/iconset.css

    r12873 r12908  
    3838.pwg-icon-category-edit {background-position: -26px -52px}
    3939.pwg-icon-sort {background-position: -52px -52px}
     40.pwg-icon-sizes {background-position: -78px -52px}
    4041.pwg-icon-category-view-normal {background-position: -156px -52px}
    4142.pwg-icon-category-view-flat {background-position: -182px -52px}
  • trunk/themes/default/template/index.tpl

    r12878 r12908  
    3636                {/strip}</li>
    3737{/if}
     38
     39{if !empty($image_derivatives)}
     40                <li>{strip}<a href="javascript:toggleImageDerivativesBox()" id="derivativeChooseLink" title="{'Photo Sizes'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
     41                        <span class="pwg-icon pwg-icon-sizes">&nbsp;</span><span class="pwg-button-text">{'Photo Sizes'|@translate}</span>
     42                </a>
     43                <div id="derivativeSwitchBox" style="display:none; text-align:left" onclick="toggleImageDerivativesBox()">
     44                        {foreach from=$image_derivatives item=image_derivative name=deriv_loop}{if !$smarty.foreach.deriv_loop.first}<br>{/if}
     45                        {if $image_derivative.SELECTED}
     46                        <span>{$image_derivative.DISPLAY}</span>
     47                        {else}
     48                        <a href="{$image_derivative.URL}" rel="nofollow">{$image_derivative.DISPLAY}</a>
     49                        {/if}
     50                        {/foreach}
     51                </div>
     52                {footer_script}{literal}
     53function toggleImageDerivativesBox()
     54{
     55        var elt = document.getElementById("derivativeSwitchBox"),
     56                ePos = document.getElementById("derivativeChooseLink");
     57        if (elt.style.display==="none")
     58        {
     59                elt.style.position = "absolute";
     60                elt.style.left = (ePos.offsetLeft) + "px";
     61                elt.style.top = (ePos.offsetTop + ePos.offsetHeight) + "px";
     62                elt.style.display="";
     63        }
     64        else
     65                elt.style.display="none";
     66}
     67                {/literal}{/footer_script}
     68                {/strip}</li>
     69{/if}
     70
    3871{if isset($favorite)}
    3972                <li><a href="{$favorite.U_FAVORITE}" title="{'delete all photos from your favorites'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
  • trunk/themes/default/template/thumbnails.tpl

    r11990 r12908  
    1 {if !empty($thumbnails)}
    2 {strip}{foreach from=$thumbnails item=thumbnail}
     1{if !empty($thumbnails)}{strip}
     2{html_head}
     3<style type="text/css">
     4{*Set some sizes according to maximum thumbnail width and height*}
     5.thumbnails SPAN,
     6.thumbnails .wrap2 A,
     7.thumbnails LABEL{ldelim}
     8        width: {$derivative_params->max_width()}px;
     9}
     10
     11.thumbnails .wrap2{ldelim}
     12        height: {$derivative_params->max_height()+2}px;
     13}
     14
     15</style>
     16{/html_head}
     17{foreach from=$thumbnails item=thumbnail}
    318        <li>
    419        <span class="wrap1">
    520                <span class="wrap2">
    621                <a href="{$thumbnail.URL}">
    7                         <img class="thumbnail" src="{$thumbnail.TN_SRC}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
     22                        <img class="thumbnail" src="{$pwg->derivative_url($derivative_params, $thumbnail.src_image)}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
    823                </a>
    924                </span>
  • trunk/themes/default/theme.css

    r12881 r12908  
    686686
    687687/* Set some sizes according to your maximum thumbnail width and height */
    688 .thumbnails SPAN,
    689 .thumbnails .wrap2 A,
    690 .thumbnails LABEL,
    691688.thumbnailCategory DIV.illustration {
    692689  width: 140px;      /* max thumbnail width + 2px */
    693690}
    694 .thumbnails .wrap2,
     691
    695692.content .thumbnailCategory .description {
    696693  height: 140px;    /* max thumbnail height + 2px */
Note: See TracChangeset for help on using the changeset viewer.