From 902c8f19278f389c53b23fcfbd0a0fe87a733372 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 22 Dec 2010 15:15:35 +0000 Subject: 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 --- admin/include/functions_upload.inc.php | 39 ++++++++++++- admin/photos_add.php | 37 ++++++++++++ admin/photos_add_settings.php | 62 ++++++++++++++------ .../default/template/photos_add_settings.tpl | 67 ++++++++++++++++++++-- 4 files changed, 182 insertions(+), 23 deletions(-) (limited to 'admin') diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index d3716948a..7eaeb90f5 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -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; +} ?> \ No newline at end of file diff --git a/admin/photos_add.php b/admin/photos_add.php index 54db3113c..889395985 100644 --- a/admin/photos_add.php +++ b/admin/photos_add.php @@ -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(); diff --git a/admin/photos_add_settings.php b/admin/photos_add_settings.php index 1b3f28d1b..0edaa3919 100644 --- a/admin/photos_add_settings.php +++ b/admin/photos_add_settings.php @@ -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 ) ); diff --git a/admin/themes/default/template/photos_add_settings.tpl b/admin/themes/default/template/photos_add_settings.tpl index d4fb74400..fe9830e9e 100644 --- a/admin/themes/default/template/photos_add_settings.tpl +++ b/admin/themes/default/template/photos_add_settings.tpl @@ -1,20 +1,48 @@ {literal} {/literal} @@ -69,6 +97,35 @@ $(document).ready(function(){ +{if $MANAGE_HD} +
+ {'High definition'|@translate} + + + + + + + + + + + + + + + + + + + + + + +
{'Maximum Width'|@translate} {'pixels'|@translate}
{'Maximum Height'|@translate} {'pixels'|@translate}
{'Image Quality'|@translate} %
+
+{/if} +

-- cgit v1.2.3