feature 2077 added: when ImageMagick is active, ability to remove or resize

the high definition version of the photo.


git-svn-id: http://piwigo.org/svn/trunk@8227 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall
2010-12-22 15:15:35 +00:00
parent 48aa7f5821
commit 902c8f1927
6 changed files with 192 additions and 23 deletions

View File

@@ -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);
@@ -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);
}
@@ -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;
}
?>

View File

@@ -103,6 +103,43 @@ $upload_form_config = array(
'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();

View File

@@ -45,26 +45,32 @@ if (isset($_POST['submit']))
// 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';
@@ -77,9 +83,24 @@ if (isset($_POST['submit']))
{
$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,
@@ -111,6 +132,8 @@ if (isset($_POST['submit']))
);
}
}
$form_values[$field] = $value;
}
if (count($page['errors']) == 0)
@@ -135,13 +158,18 @@ if (isset($_POST['submit']))
// | 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
)
);

View File

@@ -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");
$("#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();
}
}
toggleResizeFields();
$("#websize_resize").click(function () {toggleResizeFields()});
toggleHdFields();
$("#hd_keep").click(function () {toggleHdFields()});
});
</script>
{/literal}
@@ -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>

View File

@@ -764,4 +764,9 @@ $lang['Menu Management'] = 'Menus';
$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';
?>

View File

@@ -769,4 +769,9 @@ $lang['Menu Management'] = 'Menus';
$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';
?>