Skip to content

Commit

Permalink
1 bouton
Browse files Browse the repository at this point in the history
  • Loading branch information
tiritibambix committed Dec 19, 2024
1 parent 4eca0c8 commit 7820384
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
20 changes: 7 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ def resize_options(filename):
# Redimensionner l'image
@app.route('/resize/<filename>', 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)
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions templates/resize.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ <h2>Additional Options</h2>
<br>

<h2>Apply Resize</h2>
<button type="submit" name="resize_mode" value="pixels">Resize by Pixels</button>
<button type="submit" name="resize_mode" value="percent">Resize by Percentage</button>
<button type="submit">Resize</button>
</form>
</body>
</html>
</html>

0 comments on commit 7820384

Please sign in to comment.