Advertisement
Guest User

Untitled

a guest
Apr 20th, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Function to get resize percentage using Zenity
  4. get_resize_percentage() {
  5. choice=$(zenity --list --title="Resize Percentage" --text="Choose resize percentage:" --radiolist --column " " --column "Percentage" TRUE "25%" FALSE "50%" FALSE "75%" FALSE "Custom")
  6.  
  7. if [ $? -eq 1 ]; then
  8. echo "" # User clicked Cancel
  9. return 1
  10. fi
  11.  
  12. if [[ "$choice" == "Custom" ]]; then
  13. percentage=$(zenity --entry --title="Custom Resize Percentage" --text="Enter custom resize percentage (e.g., 120 for 120%):")
  14. if [ $? -eq 1 ]; then
  15. echo "" # User clicked Cancel
  16. return 1
  17. fi
  18. echo "$percentage"
  19. elif [[ -n "$choice" ]]; then
  20. echo "${choice%\%}" # Remove the % sign
  21. else
  22. echo "" # No choice selected (shouldn't happen)
  23. return 1
  24. fi
  25. }
  26.  
  27. # Get the resize percentage
  28. resize_percentage=$(get_resize_percentage)
  29.  
  30. # Exit if the user cancelled the resize percentage selection
  31. if [ -z "$resize_percentage" ]; then
  32. exit 0
  33. fi
  34.  
  35. # Get the desired output format from user input
  36. output_format=$(zenity --entry --title="Output Format" --text="Enter desired output format (e.g., jpg, png):" --entry-text="jpg")
  37.  
  38. # Check if the user clicked Cancel
  39. if [ $? -eq 1 ]; then
  40. exit 0
  41. fi
  42.  
  43. # Loop through selected files
  44. for file in "$@"; do
  45. # Generate a new filename with the resize percentage and format
  46. original_filename=$(basename "$file")
  47. extension="${original_filename##*.}"
  48. filename_without_extension="${original_filename%.*}"
  49. new_filename="${filename_without_extension}_resize${resize_percentage}.${output_format}"
  50.  
  51. # Resize and convert the image, saving it with the new filename
  52. convert "$file" -resize "${resize_percentage}%" "$(dirname "$file")/$new_filename"
  53. done
  54.  
  55. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement