Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. Help() {
  4.   # echo "Write in format: $0 -od [Original directory] -t [text] -rd [Result directory] -n [font name] -s [font size]
  5.    echo "Usage: $0 [OPTIONS]"
  6.    echo "[OPTIONS] is following"
  7.    echo "-od/--originaldir Original directory with files"
  8.    echo "-t/--text Text, which you will see in images"
  9.    echo "-rd/--resultdir Directory with result images"
  10.    echo "-n/--fontname Name of font"
  11.    echo "-s/--fontsize Size of font"
  12.    echo "-h/--help Help messages"
  13.    exit
  14. }
  15.  
  16. count_of_arguments=$#
  17.  
  18. while [ $# -gt 0 ]; do
  19.    case "$1" in
  20.        -od|--originaldir)
  21.         original_dir="$2"
  22.             shift 2
  23.             ;;  
  24.        -t|--text)
  25.         text="$2"
  26.             shift 2
  27.             ;;  
  28.        -rd|--resultdir)
  29.         result_dir="$2"
  30.             shift 2
  31.             ;;
  32.        -n|--fontname)
  33.         font_name="$2"
  34.             shift 2
  35.             ;;
  36.        -s|--fontsize)
  37.         font_size="$2"
  38.             shift 2
  39.             ;;
  40.        -h|--help)
  41.             Help
  42.             ;;
  43.         *)
  44.             break
  45.             ;;
  46.     esac
  47. done
  48.  
  49. if [[ ${count_of_arguments}<6 || ${count_of_arguments} == 0 ]]; then
  50.    echo "Wrong arguments!"
  51.    echo "Write: $0 -h or $0 --help"
  52.    exit
  53. fi
  54.  
  55. if [[ ! -d ${original_dir} ]]; then
  56.    echo "There is no such directory ${original_dir}"
  57.    exit
  58. fi
  59. echo fuck1
  60. if [[ ! -d ${result_dir} ]]; then
  61. mkdir -p ${result_dir}
  62. fi
  63. echo fuck2
  64. font=${font_name:=AvantGarde-Book}
  65. check_font=$(convert -list font | grep Font: | grep "$font")
  66.  
  67. if [[ $check_font == "" ]]; then
  68.    echo " There is no such font ${font} in libraries"
  69.    exit
  70. fi
  71.  
  72. size=${size_font:=14}
  73.  
  74. for files in $original_dir/*.jpg; do
  75.    width=`identify "$files" | cut -d '.' -f 3 | cut -d "x" -f 1`
  76.    result=`basename ${files} | cut -d '.' -f 1`
  77.    result=${result}_annotated.jpg
  78.    convert -background '#0000' -font ${font} -size ${width}х${size} caption:"${text}" "${files}" +swap -composite -gravity SouthEast $files $result_dir/$result
  79. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement