Skip to content

Commit

Permalink
feature 2077 added: when ImageMagick is active, ability to remove or …
Browse files Browse the repository at this point in the history
…resize

the high definition version of the photo.


git-svn-id: http://piwigo.org/svn/trunk@8227 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Dec 22, 2010
1 parent 48aa7f5 commit 902c8f1
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 23 deletions.
39 changes: 38 additions & 1 deletion admin/include/functions_upload.inc.php
Expand Up @@ -84,6 +84,33 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
$conf['upload_form_websize_quality'],
false
);

if (is_imagick())
{
if ($conf['upload_form_hd_keep'])
{
$need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']);

if ($conf['upload_form_hd_resize'] and $need_resize)
{
pwg_image_resize(
false,
$high_path,
$high_path,
$conf['upload_form_hd_maxwidth'],
$conf['upload_form_hd_maxheight'],
$conf['upload_form_hd_quality'],
false
);
$high_infos = pwg_image_infos($high_path);
}
}
else
{
unlink($high_path);
$high_infos = null;
}
}
}

$file_infos = pwg_image_infos($file_path);
Expand Down Expand Up @@ -250,7 +277,7 @@ function pwg_image_resize($result, $source_filepath, $destination_filepath, $max
return $result;
}

if (extension_loaded('imagick'))
if (is_imagick())
{
return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata);
}
Expand Down Expand Up @@ -520,4 +547,14 @@ function add_upload_error($upload_id, $error_message)

array_push($_SESSION['uploads_error'][$upload_id], $error_message);
}

function is_imagick()
{
if (extension_loaded('imagick'))
{
return true;
}

return false;
}
?>
37 changes: 37 additions & 0 deletions admin/photos_add.php
Expand Up @@ -103,6 +103,43 @@
'can_be_null' => false,
'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'),
),

'hd_keep' => array(
'default' => true,
'can_be_null' => false,
),

'hd_resize' => array(
'default' => false,
'can_be_null' => false,
),

'hd_maxwidth' => array(
'default' => 2000,
'min' => 500,
'max' => 20000,
'pattern' => '/^\d+$/',
'can_be_null' => false,
'error_message' => l10n('The high definition maximum width must be a number between %d and %d'),
),

'hd_maxheight' => array(
'default' => 2000,
'min' => 500,
'max' => 20000,
'pattern' => '/^\d+$/',
'can_be_null' => false,
'error_message' => l10n('The high definition maximum height must be a number between %d and %d'),
),

'hd_quality' => array(
'default' => 95,
'min' => 50,
'max' => 100,
'pattern' => '/^\d+$/',
'can_be_null' => false,
'error_message' => l10n('The high definition image quality must be a number between %d and %d'),
),
);

$inserts = array();
Expand Down
62 changes: 45 additions & 17 deletions admin/photos_add_settings.php
Expand Up @@ -45,26 +45,32 @@
// let's care about the specific checkbox that disable/enable other
// settings
$field = 'websize_resize';
$fields[] = $field;

if (empty($_POST[$field]))
{
$value = false;
}
else
if (!empty($_POST[$field]))
{
$fields[] = 'websize_maxwidth';
$fields[] = 'websize_maxheight';
$fields[] = 'websize_quality';
}

$value = true;
// hd_keep
$field = 'hd_keep';
$fields[] = $field;

if (!empty($_POST[$field]))
{
$field = 'hd_resize';
$fields[] = $field;

if (!empty($_POST[$field]))
{
$fields[] = 'hd_maxwidth';
$fields[] = 'hd_maxheight';
$fields[] = 'hd_quality';
}
}

$updates[] = array(
'param' => 'upload_form_'.$field,
'value' => boolean_to_string($value),
);
$form_values[$field] = $value;;

// and now other fields, processed in a generic way
$fields[] = 'thumb_maxwidth';
$fields[] = 'thumb_maxheight';
Expand All @@ -77,9 +83,24 @@
{
$value = $_POST[$field];
}
$form_values[$field] = $value;

if ($upload_form_config[$field]['can_be_null'] and empty($value))
if (is_bool($upload_form_config[$field]['default']))
{
if (isset($value))
{
$value = true;
}
else
{
$value = false;
}

$updates[] = array(
'param' => 'upload_form_'.$field,
'value' => boolean_to_string($value)
);
}
elseif ($upload_form_config[$field]['can_be_null'] and empty($value))
{
$updates[] = array(
'param' => 'upload_form_'.$field,
Expand Down Expand Up @@ -111,6 +132,8 @@
);
}
}

$form_values[$field] = $value;
}

if (count($page['errors']) == 0)
Expand All @@ -135,13 +158,18 @@
// | template init |
// +-----------------------------------------------------------------------+

// specific case, "websize_resize" is a checkbox
$field = 'websize_resize';
$form_values[$field] = $form_values[$field] ? 'checked="checked"' : '';
foreach (array_keys($upload_form_config) as $field)
{
if (is_bool($upload_form_config[$field]['default']))
{
$form_values[$field] = $form_values[$field] ? 'checked="checked"' : '';
}
}

$template->assign(
array(
'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL,
'MANAGE_HD' => is_imagick(),
'values' => $form_values
)
);
Expand Down
67 changes: 62 additions & 5 deletions admin/themes/default/template/photos_add_settings.tpl
@@ -1,20 +1,48 @@
{literal}
<script type="text/javascript">
$(document).ready(function(){
function toggleResizeFields() {
var checkbox = $("#websize_resize");
var needToggle = $("input[name^=websize_]").not(checkbox).parents('tr');
function toggleResizeFields(prefix) {
var checkbox = $("#"+prefix+"_resize");
var needToggle = $("input[name^="+prefix+"_]").not(checkbox).not($("#hd_keep")).parents('tr');
if ($(checkbox).is(':checked')) {
needToggle.show();
if (prefix == "websize") {
$("#hd_keep").parents("fieldset").show();
}
}
else {
needToggle.hide();
if (prefix == "websize") {
$("#hd_keep").parents("fieldset").hide();
}
}
}

toggleResizeFields();
$("#websize_resize").click(function () {toggleResizeFields()});
toggleResizeFields("websize");
$("#websize_resize").click(function () {toggleResizeFields("websize")});

toggleResizeFields("hd");
$("#hd_resize").click(function () {toggleResizeFields("hd")});

function toggleHdFields() {
var checkbox = $("#hd_keep");
var needToggle = $("input[name^=hd_]").not(checkbox).parents('tr');
if ($(checkbox).is(':checked')) {
needToggle.show();
toggleResizeFields("hd");
}
else {
needToggle.hide();
}
}

toggleHdFields();
$("#hd_keep").click(function () {toggleHdFields()});
});
</script>
{/literal}
Expand Down Expand Up @@ -69,6 +97,35 @@ $(document).ready(function(){
</table>
</fieldset>

{if $MANAGE_HD}
<fieldset>
<legend>{'High definition'|@translate}</legend>

<table>
<tr>
<th><label for="hd_keep">{'Keep high definition'|@translate}</label></th>
<td><input type="checkbox" name="hd_keep" id="hd_keep" {$values.hd_keep}></td>
</tr>
<tr>
<th><label for="hd_resize">{'Resize'|@translate}</label></th>
<td><input type="checkbox" name="hd_resize" id="hd_resize" {$values.hd_resize}></td>
</tr>
<tr>
<th>{'Maximum Width'|@translate}</th>
<td><input type="text" name="hd_maxwidth" value="{$values.hd_maxwidth}" size="4" maxlength="4"> {'pixels'|@translate}</td>
</tr>
<tr>
<th>{'Maximum Height'|@translate}</th>
<td><input type="text" name="hd_maxheight" value="{$values.hd_maxheight}" size="4" maxlength="4"> {'pixels'|@translate}</td>
</tr>
<tr>
<th>{'Image Quality'|@translate}</th>
<td><input type="text" name="hd_quality" value="{$values.hd_quality}" size="3" maxlength="3"> %</td>
</tr>
</table>
</fieldset>
{/if}

<p>
<input class="submit" type="submit" name="submit" value="{'Save Settings'|@translate}"/>
</p>
Expand Down
5 changes: 5 additions & 0 deletions language/en_UK/admin.lang.php
Expand Up @@ -764,4 +764,9 @@
$lang['automatic order'] = 'automatic order';
$lang['manual order'] = 'manual order';
$lang['Albums automatically sorted'] = 'Albums automatically sorted';

$lang['Keep high definition'] = 'Keep high definition';
$lang['The high definition maximum width must be a number between %d and %d'] = 'The high definition maximum width must be a number between %d and %d';
$lang['The high definition maximum height must be a number between %d and %d'] = 'The high definition maximum height must be a number between %d and %d';
$lang['The high definition image quality must be a number between %d and %d'] = 'The high definition image quality must be a number between %d and %d';
?>
5 changes: 5 additions & 0 deletions language/fr_FR/admin.lang.php
Expand Up @@ -769,4 +769,9 @@
$lang['automatic order'] = 'ordre automatique';
$lang['manual order'] = 'ordre manuel';
$lang['Albums automatically sorted'] = 'Les catégories ont été triées automatiquement';

$lang['Keep high definition'] = 'Conserver la haute définition';
$lang['The high definition maximum width must be a number between %d and %d'] = 'La largeur maximum pour la haute définition doit être un chiffre compris entre %d et %d';
$lang['The high definition maximum height must be a number between %d and %d'] = 'La hauteur maximum pour la haute définition doit être un chiffre compris entre %d et %d';
$lang['The high definition image quality must be a number between %d and %d'] = 'La qualité d\'image pour la haute définition doit être un chiffre compris entre %d et %d';
?>

0 comments on commit 902c8f1

Please sign in to comment.