-
-
Save vtmx/9f0ae0573670e8c0ce2f8ef91e6c1baa to your computer and use it in GitHub Desktop.
convert-imgs-to-txt.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -o errexit | |
| set -o pipefail | |
| set -o nounset | |
| if ! kdialog -v > /dev/null; then | |
| exit_error "Command not exist: kdialog" | |
| fi | |
| if ! tesseract -v > /dev/null; then | |
| exit_error "Command not exist: tesseract" | |
| fi | |
| main() { | |
| images=$(kdialog --getopenfilename . "Images jpg, png and tiff(*.jpg *.png *.tiff)" --multiple --separate-output); | |
| echo "Conveting images..." | |
| while read -r image; do | |
| image_name=$(echo "${image}" | sed -E 's/\.*.{3}$//g') | |
| tesseract -l por "${image}" "${image_name}" | |
| done <<< ${images} | |
| exit_success "Image converted with success" | |
| } | |
| exit_success() { | |
| local message="$1" | |
| local green="\033[0;32m" | |
| local color_off="\033[0m" | |
| echo -e "${green}${message}${color_off}\n" | |
| exit 0 | |
| } | |
| exit_error() { | |
| local message="$1" | |
| local red="\033[0;31m" | |
| local color_off="\033[0m" | |
| echo -e "${red}${message}${color_off}\n" | |
| exit 1 | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment