Skip to content

Commit

Permalink
feature 2548 multisize - ability to choose displayed size on index page
Browse files Browse the repository at this point in the history
-added some logs on i.php (configurable) to measure the perf

git-svn-id: http://piwigo.org/svn/trunk@12908 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Jan 17, 2012
1 parent b18e3c8 commit e693ef6
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 55 deletions.
63 changes: 60 additions & 3 deletions i.php
Expand Up @@ -28,6 +28,13 @@
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');

function get_moment()
{
$t1 = explode( ' ', microtime() );
$t2 = explode( '.', $t1[0] );
$t2 = $t1[1].'.'.$t2[1];
return $t2;
}
function trigger_action() {}
function get_extension( $filename )
{
Expand Down Expand Up @@ -63,6 +70,31 @@ function mkgetdir($dir)

// end fast bootstrap

function ilog()
{
global $conf, $ilogfh;
if (!$conf['enable_i_log']) return;
if(!$ilogfh)
{
$dir=PHPWG_ROOT_PATH.$conf['data_location'].'tmp/';
if (!mkgetdir($dir) or ! ($ilogfh=fopen($dir.'i.log', 'a')) )
return;
}
fwrite($ilogfh, date("c") );
foreach( func_get_args() as $arg)
{
fwrite($ilogfh, ' ' );
if (is_array($arg))
{
fwrite($ilogfh, implode(' ', $arg) );
}
else
{
fwrite($ilogfh, $arg);
}
}
fwrite($ilogfh, "\n");
}

function ierror($msg, $code)
{
Expand Down Expand Up @@ -92,6 +124,12 @@ function ierror($msg, $code)
exit;
}

function time_step( &$step )
{
$tmp = $step;
$step = get_moment();
return intval(1000*($step - $tmp));
}

function parse_request()
{
Expand Down Expand Up @@ -159,12 +197,11 @@ function parse_request()
}
}
array_shift($deriv);

$page['coi'] = '';
if (count($deriv) && $deriv[0][0]=='c' && $deriv[0][1]=='i')
{
$page['coi'] = substr(array_shift($deriv), 2);
preg_match('#^[a-z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
preg_match('#^[a-zA-Z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
}

if ($page['derivative_type'] == IMG_CUSTOM)
Expand All @@ -187,7 +224,8 @@ function parse_request()
}
}

if ($req[0]!='g' && $req[0]!='u')
if (!is_file(PHPWG_ROOT_PATH.$req.$ext) and
is_file(PHPWG_ROOT_PATH.'../'.$req.$ext) )
$req = '../'.$req;

$page['src_location'] = $req.$ext;
Expand Down Expand Up @@ -225,6 +263,12 @@ function send_derivative($expires)


$page=array();
$begin = $step = get_moment();
$timing=array();
foreach( explode(',','load,rotate,crop,scale,sharpen,watermark,save,send') as $k )
{
$timing[$k] = '';
}

include_once( PHPWG_ROOT_PATH .'/include/derivative_params.inc.php');
include_once( PHPWG_ROOT_PATH .'/include/derivative_std_params.inc.php');
Expand Down Expand Up @@ -287,6 +331,7 @@ function send_derivative($expires)
set_time_limit(0);

$image = new pwg_image($page['src_path']);
$timing['load'] = time_step($step);

$changes = 0;

Expand All @@ -299,18 +344,21 @@ function send_derivative($expires)
{
$changes++;
$image->crop( $crop_rect->width(), $crop_rect->height(), $crop_rect->l, $crop_rect->t);
$timing['crop'] = time_step($step);
}

if ($scaled_size)
{
$changes++;
$image->resize( $scaled_size[0], $scaled_size[1] );
$d_size = $scaled_size;
$timing['scale'] = time_step($step);
}

if ($params->sharpen)
{
$changes += $image->sharpen( $params->sharpen );
$timing['sharpen'] = time_step($step);
}

if ($params->use_watermark)
Expand Down Expand Up @@ -345,6 +393,7 @@ function send_derivative($expires)
}
}
$wm_image->destroy();
$timing['watermark'] = time_step($step);
}

// no change required - redirect to source
Expand All @@ -357,6 +406,14 @@ function send_derivative($expires)
$image->set_compression_quality( $params->quality );
$image->write( $page['derivative_path'] );
$image->destroy();
$timing['save'] = time_step($step);

send_derivative($expires);
$timing['send'] = time_step($step);

ilog('perf',
basename($page['src_path']), $o_size, $o_size[0]*$o_size[1],
basename($page['derivative_path']), $d_size, $d_size[0]*$d_size[1],
time_step($begin),
$timing);
?>
49 changes: 16 additions & 33 deletions include/category_default.inc.php
Expand Up @@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
Expand Down Expand Up @@ -104,38 +104,21 @@
array('start')
);

if (isset($nb_comments_of) )
if (isset($nb_comments_of))
{
$row['nb_comments'] = (int)@$nb_comments_of[$row['id']];
$row['NB_COMMENTS'] = $row['nb_comments'] = (int)@$nb_comments_of[$row['id']];
}

$name = get_picture_title($row);

$tpl_var = array(
'ID' => $row['id'],
$tpl_var = array_merge( $row, array(
'TN_SRC' => DerivativeImage::thumb_url($row),
'TN_ALT' => htmlspecialchars(strip_tags($name)),
'TN_TITLE' => get_thumbnail_title($row),
'URL' => $url,
'src_image' => new SrcImage($row),
) );

// Extra fields for usage in extra themes
'FILE_PATH' => $row['path'],
'FILE_POSTED' => $row['date_available'],
'FILE_CREATED' => $row['date_creation'],
'FILE_DESC' => $row['comment'],
'FILE_AUTHOR' => $row['author'],
'FILE_HIT' => $row['hit'],
'FILE_SIZE' => $row['filesize'],
'FILE_WIDTH' => $row['width'],
'FILE_HEIGHT' => $row['height'],
'FILE_METADATE' => $row['date_metadata_update'],
'FILE_HAS_HD' => $row['has_high'],
'FILE_HD_WIDTH' => $row['high_width'],
'FILE_HD_HEIGHT' => $row['high_height'],
'FILE_HD_FILESIZE' => $row['high_filesize'],
'FILE_RATING_SCORE' => $row['rating_score'],
);

if ($conf['index_new_icon'])
{
$tpl_var['icon_ts'] = get_icon($row['date_available']);
Expand All @@ -145,7 +128,7 @@
{
$tpl_var['NB_HITS'] = $row['hit'];
}

switch ($page['section'])
{
case 'best_rated' :
Expand All @@ -162,22 +145,22 @@
break;
}
}

$tpl_var['NAME'] = $name;

if (isset($row['nb_comments']))
{
$tpl_var['NB_COMMENTS'] = $row['nb_comments'];
}

$tpl_var['NAME'] = $name;
$tpl_thumbnails_var[] = $tpl_var;
}

$template->assign('SHOW_THUMBNAIL_CAPTION', $conf['show_thumbnail_caption']);
$derivative_params = ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) );

$template->assign( array(
'derivative_params' =>$derivative_params,
'SHOW_THUMBNAIL_CAPTION' =>$conf['show_thumbnail_caption'],
) );
$tpl_thumbnails_var = trigger_event('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
$template->assign('thumbnails', $tpl_thumbnails_var);

$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');

unset($pictures, $selection, $tpl_thumbnails_var);
$template->clear_assign( array('thumbnails') );
pwg_debug('end include/category_default.inc.php');
?>
5 changes: 4 additions & 1 deletion include/config_default.inc.php
Expand Up @@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
Expand Down Expand Up @@ -467,6 +467,9 @@
// gives an empty value '' to deactivate
$conf['show_php_errors'] = E_ALL;

// enable log for i derivative script
$conf['enable_i_log'] = false;

// +-----------------------------------------------------------------------+
// | authentication |
// +-----------------------------------------------------------------------+
Expand Down
12 changes: 3 additions & 9 deletions include/derivative.inc.php
Expand Up @@ -100,8 +100,6 @@ final class DerivativeImage

public $src_image;

private $requested_type;

private $flags = 0;
private $params;
private $rel_path, $rel_url;
Expand All @@ -111,12 +109,10 @@ function __construct($type, $src_image)
$this->src_image = $src_image;
if (is_string($type))
{
$this->requested_type = $type;
$this->params = ImageStdParams::get_by_type($type);
}
else
{
$this->requested_type = IMG_CUSTOM;
$this->params = $type;
}

Expand All @@ -125,14 +121,12 @@ function __construct($type, $src_image)

static function thumb_url($infos)
{
$src_image = new SrcImage($infos);
self::build($src_image, ImageStdParams::get_by_type(IMG_THUMB), $rel_path, $rel_url);
return get_root_url().$rel_url;
return self::url(IMG_THUMB, $infos);
}

static function url($type, $infos)
{
$src_image = new SrcImage($infos);
$src_image = is_object($infos) ? $infos : new SrcImage($infos);
$params = is_string($type) ? ImageStdParams::get_by_type($type) : $type;
self::build($src_image, $params, $rel_path, $rel_url);
return get_root_url().$rel_url;
Expand Down Expand Up @@ -257,7 +251,7 @@ function get_size_htm()
$size = $this->get_size();
if ($size)
{
return 'width="'.$size[0].'" height="'.$size[1].'"';
return 'width='.$size[0].' height='.$size[1];
}
}

Expand Down
10 changes: 10 additions & 0 deletions include/derivative_params.inc.php
Expand Up @@ -315,6 +315,16 @@ function compute_final_size($in_size, $coi)
return $scale_size != null ? $scale_size : $in_size;
}

function max_width()
{
return $this->sizing->ideal_size[0];
}

function max_height()
{
return $this->sizing->ideal_size[1];
}

function is_identity($in_size)
{
if ($in_size[0] > $this->sizing->ideal_size[0] or
Expand Down
7 changes: 6 additions & 1 deletion include/template.class.php
Expand Up @@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
Expand Down Expand Up @@ -842,6 +842,11 @@ function sprintf()
$args = func_get_args();
return call_user_func_array('sprintf', $args );
}

function derivative_url($type, $img)
{
return DerivativeImage::url($type, $img);
}
}


Expand Down

0 comments on commit e693ef6

Please sign in to comment.