img2text-to-file.sh 344 B

12345678910111213141516
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. display_help(){
  4. echo "Usage: ${0##*/} [extension-to-convert] [file/s]"
  5. exit 2
  6. }
  7. ext="$1"
  8. [[ $# -lt 2 || -f $ext ]] && display_help
  9. shift
  10. for img in "$@";do
  11. # tesseract "$img" "${img%.*}.${ext}"
  12. tesseract "$img" "${img%.*}"
  13. mv "${img%.*}.txt" "${img%.*}.${ext}"
  14. done