fork download
  1. #!/usr/bin/bash
  2.  
  3. extentions=("png" "jpeg" "jpg" "gif" "bmp")
  4. trueC=1
  5. falseC=0
  6.  
  7. # If the line below gives you an error, please download cowsay. sudo apt-get install cowsay . Or comment the line instead.
  8. cowsay 'Hello,' "$USER". $'My name is Cowery. I will be your guide within this program.\n Please enter the size of the image in \"300x400\" format without quotes.\n This will resize all images of format \"png, jpeg, jpg, gif, bmp\" to the size you have entered.\n Make sure you have imagemagick installed. sudo apt-get install imagemagick .'
  9.  
  10. function ArrayContains {
  11. local array="$1[@]"
  12. local seeking="$2"
  13. for element in "${!array}"; do
  14. if [[ $element == $seeking ]]; then
  15. return 1
  16. fi
  17. done
  18. return 0
  19. }
  20.  
  21. read user_input
  22. IFS=' ' read -r -a new_width_height <<< $user_input
  23.  
  24. echo $'\n'"Images resized:"
  25. for file in *
  26. do
  27. fullfilename=$(basename "$file")
  28. extention="${fullfilename##*.}"
  29. filename="${fullfilename%.*}"
  30.  
  31. ArrayContains extentions $extention
  32. if [[ $? == $trueC ]]; then
  33. new_file_name="$filename-${new_width_height[0]}-${new_width_height[1]}.$extention"
  34. echo $new_file_name
  35.  
  36. convert $fullfilename -resize ${new_width_height[0]}x${new_width_height[1]} $new_file_name
  37. # mv $fullfilename $new_file_name
  38. fi
  39. done
  40.  
  41. #END
  42.  
Success #stdin #stdout #stderr 0s 19656KB
stdin
Standard input is empty
stdout
Images resized:
stderr
./prog.sh: line 8: cowsay: command not found