Skip to content

Commit 0d27721

Browse files
author
rvelices
committed
multisize - added the coi (still to affine the admin ui + language)
multisize - derivatives can be revuild from a larger derviative instead of the original git-svn-id: http://piwigo.org/svn/trunk@13038 68402e56-0260-453c-a942-63ccdbb3a9ee
1 parent 8d86e7b commit 0d27721

15 files changed

+2204
-28
lines changed

Diff for: admin/picture_coi.php

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
// +-----------------------------------------------------------------------+
3+
// | Piwigo - a PHP based photo gallery |
4+
// +-----------------------------------------------------------------------+
5+
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
6+
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
7+
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
8+
// +-----------------------------------------------------------------------+
9+
// | This program is free software; you can redistribute it and/or modify |
10+
// | it under the terms of the GNU General Public License as published by |
11+
// | the Free Software Foundation |
12+
// | |
13+
// | This program is distributed in the hope that it will be useful, but |
14+
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
15+
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16+
// | General Public License for more details. |
17+
// | |
18+
// | You should have received a copy of the GNU General Public License |
19+
// | along with this program; if not, write to the Free Software |
20+
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21+
// | USA. |
22+
// +-----------------------------------------------------------------------+
23+
24+
if(!defined("PHPWG_ROOT_PATH"))
25+
{
26+
die('Hacking attempt!');
27+
}
28+
29+
// +-----------------------------------------------------------------------+
30+
// | Check Access and exit when user status is not ok |
31+
// +-----------------------------------------------------------------------+
32+
check_status(ACCESS_ADMINISTRATOR);
33+
34+
check_input_parameter('image_id', $_GET, false, PATTERN_ID);
35+
36+
if (isset($_POST['submit']))
37+
{
38+
$query = 'UPDATE '.IMAGES_TABLE;
39+
if (strlen($_POST['l'])==0)
40+
{
41+
$query .= ' SET coi=NULL';
42+
}
43+
else
44+
{
45+
$coi = fraction_to_char($_POST['l'])
46+
.fraction_to_char($_POST['t'])
47+
.fraction_to_char($_POST['r'])
48+
.fraction_to_char($_POST['b']);
49+
$query .= ' SET coi=\''.$coi.'\'';
50+
}
51+
$query .= ' WHERE id='.$_GET['image_id'];
52+
pwg_query($query);
53+
}
54+
55+
$query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$_GET['image_id'];
56+
$row = pwg_db_fetch_assoc( pwg_query($query) );
57+
58+
if (isset($_POST['submit']))
59+
{
60+
delete_element_derivatives($row);
61+
}
62+
63+
$tpl_var = array(
64+
'ALT' => $row['file'],
65+
'U_IMG' => DerivativeImage::url(IMG_LARGE, $row),
66+
'U_EDIT' => get_root_url().'admin.php?page=picture_modify&amp;image_id='.$_GET['image_id'],
67+
);
68+
69+
if (!empty($row['coi']))
70+
{
71+
$tpl_var['coi'] = array(
72+
'l'=> char_to_fraction($row['coi'][0]),
73+
't'=> char_to_fraction($row['coi'][1]),
74+
'r'=> char_to_fraction($row['coi'][2]),
75+
'b'=> char_to_fraction($row['coi'][3]),
76+
);
77+
}
78+
79+
if (isset($_POST['submit']))
80+
{
81+
$uid = '&b='.time();
82+
$conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true;
83+
$conf['derivative_url_style']=2; //script
84+
$tpl_var['U_SQUARE'] = DerivativeImage::url(IMG_SQUARE, $row).$uid;
85+
$tpl_var['U_THUMB'] = DerivativeImage::url(IMG_THUMB, $row).$uid;
86+
}
87+
else
88+
{
89+
$tpl_var['U_SQUARE'] = DerivativeImage::url(IMG_SQUARE, $row);
90+
$tpl_var['U_THUMB'] = DerivativeImage::url(IMG_THUMB, $row);
91+
}
92+
93+
$template->assign($tpl_var);
94+
$template->set_filename('picture_coi', 'picture_coi.tpl');
95+
96+
$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_coi');
97+
?>

Diff for: admin/picture_modify.php

+5
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@
303303
)
304304
);
305305

306+
if (in_array(get_extension($row['path']),$conf['picture_ext']))
307+
{
308+
$template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&amp;image_id='.$_GET['image_id']);
309+
}
310+
306311
// image level options
307312
$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
308313
$template->assign(

Diff for: admin/themes/default/template/picture_coi.tpl

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{html_head}
2+
<link rel="stylesheet" type="text/css" href="themes/default/js/plugins/jquery.Jcrop.css" />
3+
{/html_head}
4+
{combine_script id='jquery.jcrop' load='footer' require='jquery' path='themes/default/js/plugins/jquery.Jcrop.min.js'}
5+
6+
<h2>{'Center of interest'|@translate}</h2>
7+
<div>
8+
<a href="{$U_EDIT}">{'Edit photo information'|@translate}</a>
9+
</div>
10+
11+
<div>
12+
<img src="{$U_SQUARE}" alt="{$ALT}">
13+
<img src="{$U_THUMB}" alt="{$ALT}">
14+
</div>
15+
16+
<div>
17+
<form method="post">
18+
<input type="hidden" id="l" name="l" value="{if isset($coi)}{$coi.l}{/if}">
19+
<input type="hidden" id="t" name="t" value="{if isset($coi)}{$coi.t}{/if}">
20+
<input type="hidden" id="r" name="r" value="{if isset($coi)}{$coi.r}{/if}">
21+
<input type="hidden" id="b" name="b" value="{if isset($coi)}{$coi.b}{/if}">
22+
23+
<img id="jcrop" src="{$U_IMG}" alt="{$ALT}">
24+
25+
<p>
26+
<input type="submit" name="submit" value="{'Submit'|@translate}">
27+
</p>
28+
</form>
29+
</div>
30+
31+
{footer_script}
32+
{literal}
33+
function from_coi(f, total) {
34+
return f*total;
35+
}
36+
37+
function to_coi(v, total) {
38+
return v/total;
39+
}
40+
41+
function jOnChange(sel) {
42+
var $img = jQuery("#jcrop");
43+
jQuery("#l").val( to_coi(sel.x, $img.width()) );
44+
jQuery("#t").val( to_coi(sel.y, $img.height()) );
45+
jQuery("#r").val( to_coi(sel.x2, $img.width()) );
46+
jQuery("#b").val( to_coi(sel.y2, $img.height()) );
47+
}
48+
function jOnRelease() {
49+
jQuery("#l,#t,#r,#b").val("");
50+
}
51+
52+
{/literal}
53+
jQuery("#jcrop").Jcrop( {ldelim}
54+
boxWidth: 400, boxHeight: 400,
55+
onChange: jOnChange,
56+
onRelease: jOnRelease
57+
}
58+
{if isset($coi)}
59+
,function() {ldelim}
60+
var $img = jQuery("#jcrop");
61+
this.animateTo( [from_coi({$coi.l}, $img.width()), from_coi({$coi.t}, $img.height()), from_coi({$coi.r}, $img.width()), from_coi({$coi.b}, $img.height()) ] );
62+
}
63+
{/if}
64+
);
65+
{/footer_script}
66+

Diff for: admin/themes/default/template/picture_modify.tpl

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ pwg_initialization_datepicker("#date_creation_day", "#date_creation_month", "#da
8383
</td>
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

8994
</fieldset>

Diff for: i.php

+87-9
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,6 @@ function parse_request()
232232
}
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)
243237
{
@@ -256,7 +250,7 @@ function parse_request()
256250
{
257251
ierror('Too big', 403);
258252
}
259-
253+
260254
$key = array();
261255
$params->add_url_tokens($key);
262256
$key = implode('_', $key);
@@ -266,15 +260,65 @@ function parse_request()
266260
}
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;
274273
$page['src_path'] = PHPWG_ROOT_PATH.$page['src_location'];
275274
$page['src_url'] = $page['root_path'].$page['src_location'];
276275
}
277276

277+
function 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

279323
function send_derivative($expires)
280324
{
@@ -362,6 +406,40 @@ function send_derivative($expires)
362406
send_derivative($expires);
363407
}
364408

409+
$page['coi'] = null;
410+
if (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+
441+
try_switch_source($params, $src_mtime);
442+
365443
if (!mkgetdir(dirname($page['derivative_path'])))
366444
{
367445
ierror("dir create error", 500);

Diff for: include/dblayer/functions_mysql.inc.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ function pwg_query($query)
8484
{
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']))
9393
{
@@ -199,7 +199,7 @@ function array_from_query($query, $fieldname)
199199
$result = pwg_query($query);
200200
while ($row = mysql_fetch_assoc($result))
201201
{
202-
array_push($array, $row[$fieldname]);
202+
$array[] = $row[$fieldname];
203203
}
204204

205205
return $array;

Diff for: include/derivative.inc.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ final class SrcImage
2727
public $id;
2828
public $rel_path;
2929

30-
public $coi=null;
3130
private $size=null;
3231
private $flags=0;
3332

3433
function __construct($infos)
3534
{
3635
global $conf;
37-
36+
3837
$this->id = $infos['id'];
3938
$ext = get_extension($infos['path']);
4039
if (in_array($ext, $conf['picture_ext']))
@@ -54,7 +53,6 @@ function __construct($infos)
5453
$this->size = @getimagesize(PHPWG_ROOT_PATH.$this->rel_path);
5554
}
5655

57-
$this->coi = @$infos['coi'];
5856
if (!$this->size && isset($infos['width']) && isset($infos['height']))
5957
{
6058
$this->size = array($infos['width'], $infos['height']);
@@ -168,11 +166,6 @@ private static function build($src, &$params, &$rel_path, &$rel_url)
168166
$tokens=array();
169167
$tokens[] = substr($params->type,0,2);
170168

171-
if ($params->sizing->max_crop != 0 and !empty($src->coi))
172-
{
173-
$tokens[] = 'ci'.$src->coi;
174-
}
175-
176169
if ($params->type==IMG_CUSTOM)
177170
{
178171
$params->add_url_tokens($tokens);
@@ -257,7 +250,7 @@ function get_size()
257250
{
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

263256
function get_size_htm()

0 commit comments

Comments
 (0)