Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Function to get resize percentage using Zenity
- get_resize_percentage() {
- choice=$(zenity --list --title="Resize Percentage" --text="Choose resize percentage:" --radiolist --column " " --column "Percentage" TRUE "25%" FALSE "50%" FALSE "75%" FALSE "Custom")
- if [ $? -eq 1 ]; then
- echo "" # User clicked Cancel
- return 1
- fi
- if [[ "$choice" == "Custom" ]]; then
- percentage=$(zenity --entry --title="Custom Resize Percentage" --text="Enter custom resize percentage (e.g., 120 for 120%):")
- if [ $? -eq 1 ]; then
- echo "" # User clicked Cancel
- return 1
- fi
- echo "$percentage"
- elif [[ -n "$choice" ]]; then
- echo "${choice%\%}" # Remove the % sign
- else
- echo "" # No choice selected (shouldn't happen)
- return 1
- fi
- }
- # Get the resize percentage
- resize_percentage=$(get_resize_percentage)
- # Exit if the user cancelled the resize percentage selection
- if [ -z "$resize_percentage" ]; then
- exit 0
- fi
- # Get the desired output format from user input
- output_format=$(zenity --entry --title="Output Format" --text="Enter desired output format (e.g., jpg, png):" --entry-text="jpg")
- # Check if the user clicked Cancel
- if [ $? -eq 1 ]; then
- exit 0
- fi
- # Loop through selected files
- for file in "$@"; do
- # Generate a new filename with the resize percentage and format
- original_filename=$(basename "$file")
- extension="${original_filename##*.}"
- filename_without_extension="${original_filename%.*}"
- new_filename="${filename_without_extension}_resize${resize_percentage}.${output_format}"
- # Resize and convert the image, saving it with the new filename
- convert "$file" -resize "${resize_percentage}%" "$(dirname "$file")/$new_filename"
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement