feature 2548 multisize - ability to choose displayed size on index page
-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
63
i.php
|
@ -28,6 +28,13 @@ include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
|
|||
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 )
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
|
@ -287,6 +331,7 @@ ignore_user_abort(true);
|
|||
set_time_limit(0);
|
||||
|
||||
$image = new pwg_image($page['src_path']);
|
||||
$timing['load'] = time_step($step);
|
||||
|
||||
$changes = 0;
|
||||
|
||||
|
@ -299,6 +344,7 @@ if ($crop_rect)
|
|||
{
|
||||
$changes++;
|
||||
$image->crop( $crop_rect->width(), $crop_rect->height(), $crop_rect->l, $crop_rect->t);
|
||||
$timing['crop'] = time_step($step);
|
||||
}
|
||||
|
||||
if ($scaled_size)
|
||||
|
@ -306,11 +352,13 @@ 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)
|
||||
|
@ -345,6 +393,7 @@ if ($params->use_watermark)
|
|||
}
|
||||
}
|
||||
$wm_image->destroy();
|
||||
$timing['watermark'] = time_step($step);
|
||||
}
|
||||
|
||||
// no change required - redirect to source
|
||||
|
@ -357,6 +406,14 @@ if (!$changes)
|
|||
$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);
|
||||
?>
|
|
@ -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 |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
@ -104,37 +104,20 @@ foreach ($pictures as $row)
|
|||
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,
|
||||
|
||||
// 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'],
|
||||
);
|
||||
'src_image' => new SrcImage($row),
|
||||
) );
|
||||
|
||||
if ($conf['index_new_icon'])
|
||||
{
|
||||
|
@ -164,20 +147,20 @@ foreach ($pictures as $row)
|
|||
}
|
||||
|
||||
$tpl_var['NAME'] = $name;
|
||||
|
||||
if (isset($row['nb_comments']))
|
||||
{
|
||||
$tpl_var['NB_COMMENTS'] = $row['nb_comments'];
|
||||
}
|
||||
|
||||
$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');
|
||||
?>
|
|
@ -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 |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
@ -467,6 +467,9 @@ $conf['template_combine_files'] = true;
|
|||
// gives an empty value '' to deactivate
|
||||
$conf['show_php_errors'] = E_ALL;
|
||||
|
||||
// enable log for i derivative script
|
||||
$conf['enable_i_log'] = false;
|
||||
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | authentication |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
|
|
@ -100,8 +100,6 @@ final class DerivativeImage
|
|||
|
||||
public $src_image;
|
||||
|
||||
private $requested_type;
|
||||
|
||||
private $flags = 0;
|
||||
private $params;
|
||||
private $rel_path, $rel_url;
|
||||
|
@ -111,12 +109,10 @@ final class DerivativeImage
|
|||
$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;
|
||||
}
|
||||
|
||||
|
@ -125,14 +121,12 @@ final class DerivativeImage
|
|||
|
||||
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;
|
||||
|
@ -257,7 +251,7 @@ final class DerivativeImage
|
|||
$size = $this->get_size();
|
||||
if ($size)
|
||||
{
|
||||
return 'width="'.$size[0].'" height="'.$size[1].'"';
|
||||
return 'width='.$size[0].' height='.$size[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -315,6 +315,16 @@ final class DerivativeParams
|
|||
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
|
||||
|
|
|
@ -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 |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
@ -842,6 +842,11 @@ class PwgTemplateAdapter
|
|||
$args = func_get_args();
|
||||
return call_user_func_array('sprintf', $args );
|
||||
}
|
||||
|
||||
function derivative_url($type, $img)
|
||||
{
|
||||
return DerivativeImage::url($type, $img);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
32
index.php
|
@ -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 |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
@ -60,6 +60,14 @@ if (isset($_GET['image_order']))
|
|||
)
|
||||
);
|
||||
}
|
||||
if (isset($_GET['display']))
|
||||
{
|
||||
$page['meta_robots']['noindex']=1;
|
||||
if (array_key_exists($_GET['display'], ImageStdParams::get_defined_type_map()))
|
||||
{
|
||||
pwg_set_session_var('index_deriv', $_GET['display']);
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------- initialization
|
||||
|
||||
$page['navigation_bar'] = array();
|
||||
|
@ -252,6 +260,28 @@ if ( $conf['index_sort_order_input']
|
|||
}
|
||||
}
|
||||
|
||||
if ( count($page['items']) > 0 )
|
||||
{
|
||||
$url = add_url_params(
|
||||
duplicate_index_url(),
|
||||
array('display' => '')
|
||||
);
|
||||
$selected_type = pwg_get_session_var('index_deriv', IMG_THUMB);
|
||||
$type_map = ImageStdParams::get_defined_type_map();
|
||||
unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]);
|
||||
foreach($type_map as $params)
|
||||
{
|
||||
$template->append(
|
||||
'image_derivatives',
|
||||
array(
|
||||
'DISPLAY' => l10n($params->type),
|
||||
'URL' => $url.$params->type,
|
||||
'SELECTED' => ($params->type == $selected_type ? true:false),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// category comment
|
||||
if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
.pwg-icon-close {background-position: 0 -52px}
|
||||
.pwg-icon-category-edit {background-position: -26px -52px}
|
||||
.pwg-icon-sort {background-position: -52px -52px}
|
||||
.pwg-icon-sizes {background-position: -78px -52px}
|
||||
.pwg-icon-category-view-normal {background-position: -156px -52px}
|
||||
.pwg-icon-category-view-flat {background-position: -182px -52px}
|
||||
|
||||
|
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.2 KiB |
|
@ -35,6 +35,39 @@ function toggleSortOrderBox()
|
|||
{/literal}{/footer_script}
|
||||
{/strip}</li>
|
||||
{/if}
|
||||
|
||||
{if !empty($image_derivatives)}
|
||||
<li>{strip}<a href="javascript:toggleImageDerivativesBox()" id="derivativeChooseLink" title="{'Photo Sizes'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
|
||||
<span class="pwg-icon pwg-icon-sizes"> </span><span class="pwg-button-text">{'Photo Sizes'|@translate}</span>
|
||||
</a>
|
||||
<div id="derivativeSwitchBox" style="display:none; text-align:left" onclick="toggleImageDerivativesBox()">
|
||||
{foreach from=$image_derivatives item=image_derivative name=deriv_loop}{if !$smarty.foreach.deriv_loop.first}<br>{/if}
|
||||
{if $image_derivative.SELECTED}
|
||||
<span>{$image_derivative.DISPLAY}</span>
|
||||
{else}
|
||||
<a href="{$image_derivative.URL}" rel="nofollow">{$image_derivative.DISPLAY}</a>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
{footer_script}{literal}
|
||||
function toggleImageDerivativesBox()
|
||||
{
|
||||
var elt = document.getElementById("derivativeSwitchBox"),
|
||||
ePos = document.getElementById("derivativeChooseLink");
|
||||
if (elt.style.display==="none")
|
||||
{
|
||||
elt.style.position = "absolute";
|
||||
elt.style.left = (ePos.offsetLeft) + "px";
|
||||
elt.style.top = (ePos.offsetTop + ePos.offsetHeight) + "px";
|
||||
elt.style.display="";
|
||||
}
|
||||
else
|
||||
elt.style.display="none";
|
||||
}
|
||||
{/literal}{/footer_script}
|
||||
{/strip}</li>
|
||||
{/if}
|
||||
|
||||
{if isset($favorite)}
|
||||
<li><a href="{$favorite.U_FAVORITE}" title="{'delete all photos from your favorites'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
|
||||
<span class="pwg-icon pwg-icon-favorite-del"> </span><span class="pwg-button-text">{'delete all photos from your favorites'|@translate}</span>
|
||||
|
|
|
@ -1,10 +1,25 @@
|
|||
{if !empty($thumbnails)}
|
||||
{strip}{foreach from=$thumbnails item=thumbnail}
|
||||
{if !empty($thumbnails)}{strip}
|
||||
{html_head}
|
||||
<style type="text/css">
|
||||
{*Set some sizes according to maximum thumbnail width and height*}
|
||||
.thumbnails SPAN,
|
||||
.thumbnails .wrap2 A,
|
||||
.thumbnails LABEL{ldelim}
|
||||
width: {$derivative_params->max_width()}px;
|
||||
}
|
||||
|
||||
.thumbnails .wrap2{ldelim}
|
||||
height: {$derivative_params->max_height()+2}px;
|
||||
}
|
||||
|
||||
</style>
|
||||
{/html_head}
|
||||
{foreach from=$thumbnails item=thumbnail}
|
||||
<li>
|
||||
<span class="wrap1">
|
||||
<span class="wrap2">
|
||||
<a href="{$thumbnail.URL}">
|
||||
<img class="thumbnail" src="{$thumbnail.TN_SRC}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
|
||||
<img class="thumbnail" src="{$pwg->derivative_url($derivative_params, $thumbnail.src_image)}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
|
||||
</a>
|
||||
</span>
|
||||
{if $SHOW_THUMBNAIL_CAPTION }
|
||||
|
|
|
@ -685,13 +685,10 @@ IMG.ui-datepicker-trigger {
|
|||
}
|
||||
|
||||
/* Set some sizes according to your maximum thumbnail width and height */
|
||||
.thumbnails SPAN,
|
||||
.thumbnails .wrap2 A,
|
||||
.thumbnails LABEL,
|
||||
.thumbnailCategory DIV.illustration {
|
||||
width: 140px; /* max thumbnail width + 2px */
|
||||
}
|
||||
.thumbnails .wrap2,
|
||||
|
||||
.content .thumbnailCategory .description {
|
||||
height: 140px; /* max thumbnail height + 2px */
|
||||
}
|
||||
|
|