From 78203847f26746d3307966e30f7088e2ec952ef7 Mon Sep 17 00:00:00 2001 From: tiritibambix Date: Thu, 19 Dec 2024 01:17:53 +0100 Subject: [PATCH] 1 bouton --- app.py | 20 +++++++------------- templates/resize.html | 5 ++--- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index 40eb7ba..02a4834 100644 --- a/app.py +++ b/app.py @@ -84,10 +84,13 @@ def resize_options(filename): # Redimensionner l'image @app.route('/resize/', methods=['POST']) def resize_image(filename): - resize_mode = request.form.get('resize_mode', '') quality = request.form.get('quality', '100') # Valeur par défaut : 100% format_conversion = request.form.get('format', None) keep_ratio = 'keep_ratio' in request.form # Checkbox pour garder le ratio + width = request.form.get('width', '') + height = request.form.get('height', '') + percentage = request.form.get('percentage', '') + filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) output_filename = filename output_path = os.path.join(app.config['OUTPUT_FOLDER'], output_filename) @@ -98,21 +101,12 @@ def resize_image(filename): try: # Déterminer les options de redimensionnement - if resize_mode == 'pixels': - width = request.form.get('width', '') - height = request.form.get('height', '') - if not width.isdigit() or not height.isdigit(): - flash('Dimensions invalides.') - return redirect(url_for('resize_options', filename=filename)) + if width.isdigit() and height.isdigit(): resize_value = f"{width}x{height}" if not keep_ratio else f"{width}x{height}!" - elif resize_mode == 'percent': - percentage = request.form.get('percentage', '') - if not percentage.isdigit() or int(percentage) <= 0 or int(percentage) > 100: - flash('Pourcentage invalide.') - return redirect(url_for('resize_options', filename=filename)) + elif percentage.isdigit() and 0 < int(percentage) <= 100: resize_value = f"{percentage}%" else: - flash('Mode de redimensionnement invalide.') + flash('Veuillez spécifier soit des dimensions (width/height), soit un pourcentage valide.') return redirect(url_for('resize_options', filename=filename)) # Commande ImageMagick diff --git a/templates/resize.html b/templates/resize.html index 2888821..f1bb9c2 100644 --- a/templates/resize.html +++ b/templates/resize.html @@ -31,8 +31,7 @@

Additional Options


Apply Resize

- - + - \ No newline at end of file +