no-parts

tmka.sh

Jan 20th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 11.51 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. tput clear
  4.  
  5. tput cup 2 50
  6. tput setaf 3
  7. echo "
  8.   _|                      _|
  9. _|_|_|_|  _|_|_|  _|_|    _|  _|      _|_|_|  
  10.   _|      _|    _|    _|  _|_|      _|    _|  
  11.   _|      _|    _|    _|  _|  _|    _|    _|  
  12.     _|_|  _|    _|    _|  _|    _|    _|_|_| "
  13.  
  14. tput sgr0
  15.  
  16. tput cup 9 17
  17.  
  18. tput rev
  19. echo -e "\033[33mTHIS MACHINE KILLS ASCIIS\033[0m"
  20. tput sgr0
  21.  
  22. tput cup 11 15
  23. echo -e "\033[33m     is the 3rd part of KUNST-WERK-ZEUG\033[0m"
  24.  
  25. tput cup 12 22
  26. echo -e "\033[33m  http://noparts.org/kwz\033[0m"
  27.  
  28. tput cup 17 3
  29. echo -e "\033[35m to start -tmka-:\033[0m"
  30.  
  31. tput cup 20 5
  32. echo -e "\033[31m        >> !This Window have to be active! <<\033[0m"
  33.  
  34. tput bold
  35. tput cup 18 5
  36. read -p "DROP AN IMAGE OR TEXTFILE INTO THIS WINDOW [and press ENTER] " file
  37. clear
  38. tput bold
  39. tput cup 6 5
  40. echo -e "\033[32m$file will be transformed into: \033[0m"
  41.  
  42. file="$(echo $file | sed -e "s/'//" | sed -e "s/'//")"
  43.  
  44. # um die leerzeilen in den dateinamen zu umgehen
  45. IFS=$'\n'
  46.  
  47.  
  48. #-----------------------img2txt------------------------------------------------------------------
  49. clear
  50. tput bold
  51. tput cup 9 10
  52. echo -e "\033[31mplease wait while Transformation-Process... \033[0m"
  53.  
  54.  
  55. # if - eine bilddatei gewählt wird, -then:
  56.  
  57. if [[ $file = @(*.jpg|*.bmp|*.JPG|*.BMP|*.tiff|*.tif|*.TIFF|*.TIF|*.gif|*GIF|*.JPEG|*.jpeg|*.png|*.PNG) ]]
  58.  
  59. then    tput clear
  60.     tput bold
  61.     read -p "
  62.  
  63.     Type (a) for: >a space between artistic and natural language<
  64.  
  65.     Type (p) for: >pure artistic language<
  66.    
  67.         ...after your choice >> press ENTER    
  68.  
  69.        "
  70.  
  71. #-----with angram finder------
  72.  
  73.  
  74.     if  [ "$REPLY" == "a" ]
  75.     then    trap "echo BANG" SIGINT
  76.         clear
  77.         tput bold
  78.         tput cup 9 10
  79.         echo -e "\033[31mpress F11 to read in fullscreen-mode
  80.  
  81.         F11 wont work on Macs...\033[0m"
  82.         sleep 1
  83.         notify-send "to interrupt press STRG + C"
  84.         sleep 5
  85.         clear
  86.         convert $file $file.bmp
  87.         hd $file.bmp|
  88.         cut -c62-77|
  89.        
  90.         sed 's/[^[:alpha:]]//g;'|
  91.                 sed -e "/^ *$/d"|
  92.         while   read x
  93.         do  an -n 1 $x|
  94.                 tr "\n" " "
  95.         done 2>&1 |tee /dev/tty >$file-as-ASCII.txt
  96.         cp $file-as-ASCII.txt ~/Desktop
  97.             clear
  98.                 tput bold
  99.                 tput cup 4 10
  100.                 echo -e "
  101.  
  102.        a copy of <Image-File_as.txt> lies on your Desktop...
  103.  
  104. Thank you
  105.  
  106. "
  107.     rm $file-as-ASCII.txt $file.bmp
  108.            
  109.        
  110.     fi
  111.  
  112.    
  113. #----without anagram finder------
  114.  
  115.     if  [ "$REPLY" == "p" ]
  116.     then    trap "echo BANG" SIGINT
  117.         clear
  118.         tput bold
  119.         tput cup 9 10
  120.         echo -e "\033[31mpress F11 to read in fullscreen-mode
  121.  
  122.         F11 wont work on Macs... \033[0m"
  123.         sleep 1
  124.                 notify-send "to interrupt press STRG + C"
  125.         sleep 5
  126.         clear
  127.         convert $file $file.bmp
  128.         hd $file.bmp|
  129.         cut -c62-77|
  130.         tr "\n" " "|
  131.         sed 's/[.]//g;'|   
  132.         pv -qL 7000 2>&1 |tee /dev/tty >$file-as-ASCII.txt
  133.         cp $file-as-ASCII.txt ~/Desktop
  134.             clear
  135.                 tput bold
  136.                 tput cup 4 10
  137.                 echo -e "
  138.  
  139.        a copy of <Image-File_as.txt> lies on your Desktop...
  140.  
  141. Thank you
  142.  
  143. "
  144.     rm $file-as-ASCII.txt $file.bmp
  145.     fi
  146.  
  147. else echo -e "\033[34m
  148.  
  149. OH SHIT! i was never been into this space...
  150.  
  151. Sorry, but if you want to define a new one,
  152. you have to open the door by yourself and modify -tmka-
  153.  
  154. -------------------
  155.  
  156. Remember:
  157.  
  158. tmka >> can only read:
  159.  
  160.        .txt and .pdf for your Textfiles
  161.  
  162.        .png .jpg .tif .gif .bmp for your Imagefiles
  163.  
  164. tmka >> cannot handle Videofiles or anything else
  165.  
  166.  
  167. \033[0m"
  168.  
  169. fi
  170.  
  171.  
  172. #----------------------txt2img-----------------------------------------------------------------
  173.  
  174.  
  175. if      [[ $file = @(*.txt|*.TXT) ]]
  176. then        clear
  177.         tput bold
  178.         tput cup 9 10
  179.         echo -e "\033[31mplease wait while transformating... \033[0m
  180.  
  181. "
  182.         #bmp oder textfile in hexdump umwandeln
  183.         cat $file|hd|cut -c11-58>/tmp/bloblo.tmp
  184.  
  185.         hexdump=$(cat /tmp/bloblo.tmp)
  186.  
  187.         #Quadratwurzel errechnen über die Anzahl der Farbwerte (Pixel)
  188.         hexnum=`wc -w /tmp/bloblo.tmp|cut -d " " -f1`
  189.         lines=$(($hexnum/6))
  190.  
  191.         #quadratwurzel ziehen für zeilenanfänge
  192.         quadratwurzel=`echo "sqrt($lines)" | bc`
  193.  
  194.         #dezimal Quadratwurzel in Hexadezimal umrechnen
  195.         hexquadrat=$(printf "%02x\n" "$quadratwurzel")
  196.         count=$(printf "%02x\n" "$quadratwurzel"|wc -c)
  197.  
  198.         #Abfrage nach der Größe der Hexadezimalzahl (wieviele Ziffern)
  199.         eins=$(echo $hexquadrat|cut -c1)
  200.         zwei=$(echo $hexquadrat|cut -c2)
  201.         drei=$(echo $hexquadrat|cut -c3)
  202.         vier=$(echo $hexquadrat|cut -c4)
  203.         fuenf=$(echo $hexquadrat|cut -c5)
  204.         sechs=$(echo $hexquadrat|cut -c6)
  205.         sieben=$(echo $hexquadrat|cut -c7)
  206.         acht=$(echo $hexquadrat|cut -c8)
  207.  
  208.         #schreiben des Headers bzw. des kompletten Bmp-Hexdumps
  209.         if [[ $count = [1-3] ]]
  210.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  211. 00 00 $eins$zwei 00 00 00 $eins$zwei 00 00 00 01 00 18 00 00 00
  212. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  213. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  214.         fi
  215.  
  216.         if [[ $count = 4 ]]
  217.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  218. 00 00 $zwei$drei 0$eins 00 00 $zwei$drei 0$eins 00 00 01 00 18 00 00 00
  219. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  220. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  221.         fi
  222.  
  223.         if [[ $count = 5 ]]
  224.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  225. 00 00 $drei$vier $eins$zwei 00 00 $drei$vier $eins$zwei 00 00 01 00 18 00 00 00
  226. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  227. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  228.         fi
  229.  
  230.         if [[ $count = 6 ]]
  231.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  232. 00 00 $vier$fuenf $zwei$drei 0$eins 00 $vier$fuenf $zwei$drei 0$eins 00 01 00 18 00 00 00
  233. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  234. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  235.         fi
  236.  
  237.         if [[ $count = 7 ]]
  238.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  239. 00 00 $fuenf$sechs $drei$vier $eins$zwei 00 $fuenf$sechs $drei$vier $eins$zwei 00 01 00 18 00 00 00
  240. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  241. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  242.         fi
  243.  
  244.         if [[ $count = 8 ]]
  245.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  246. 00 00 $sechs$sieben $vier$fuenf $zwei$drei 0$eins $sechs$sieben $vier$fuenf $zwei$drei 0$eins 01 00 18 00 00 00
  247. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  248. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  249.         fi
  250.  
  251.         if [[ $count = 9 ]]
  252.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  253. 00 00 $sieben$acht $fuenf$sechs $drei$vier $eins$zwei $sieben$acht $fuenf$sechs $drei$vier $eins$zwei 01 00 18 00 00 00
  254. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  255. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  256.         fi
  257.  
  258.         #umwandeln des Hexdumps in ASCII (Bmp erzeugen) und als Bild visualisieren
  259.         cat /tmp/blabla.tmp |cut -c-48|xxd -r -p>$file-square.bmp
  260.         rm /tmp/blabla.tmp /tmp/bloblo.tmp
  261.         notify-send "See"
  262.         eog $file-square.bmp
  263.         cp $file-square.bmp ~/Desktop
  264.                 clear
  265.                 tput bold
  266.                 tput cup 3 10
  267.                 echo -e "
  268.  
  269.        a copy of <your-txt_as.bmp> lies on your Desktop...
  270.  
  271. Thank you
  272.  
  273. "
  274.         rm $file-square.bmp
  275.  
  276. else echo -e "\033[34m
  277.  
  278. OH SHIT! i was never been into this space...
  279.  
  280. Sorry, but if you want to define a new one,
  281. you have to open the door by yourself and modify -tmka-
  282.  
  283. -------------------
  284.  
  285. Remember:
  286.  
  287. tmka >> can only read:
  288.  
  289.        .txt and .pdf for your Textfiles
  290.  
  291.        .png .jpg .tif .gif .bmp for your Imagefiles
  292.  
  293. tmka >> cannot handle Videofiles or anything else
  294.  
  295.  
  296. \033[0m"
  297.  
  298. fi
  299.  
  300. #--------------------------------------------
  301.  
  302.  
  303. if      [[ $file = @(*.pdf|*.PDF) ]]
  304. then        pdftotext $file /tmp/dd.txt
  305.         clear
  306.         tput bold
  307.         tput cup 9 10
  308.         echo -e "\033[31mplease wait while transformating... \033[0m
  309.  
  310. "
  311.         #bmp oder textfile in hexdump umwandeln
  312.         cat /tmp/dd.txt|hd|cut -c11-58>/tmp/bloblo.tmp
  313.  
  314.         hexdump=$(cat /tmp/bloblo.tmp)
  315.  
  316.         #Quadratwurzel errechnen über die Anzahl der Farbwerte (Pixel)
  317.         hexnum=`wc -w /tmp/bloblo.tmp|cut -d " " -f1`
  318.         lines=$(($hexnum/6))
  319.  
  320.         #quadratwurzel ziehen für zeilenanfänge
  321.         quadratwurzel=`echo "sqrt($lines)" | bc`
  322.  
  323.         #dezimal Quadratwurzel in Hexadezimal umrechnen
  324.         hexquadrat=$(printf "%02x\n" "$quadratwurzel")
  325.         count=$(printf "%02x\n" "$quadratwurzel"|wc -c)
  326.  
  327.         #Abfrage nach der Größe der Hexadezimalzahl (wieviele Ziffern)
  328.         eins=$(echo $hexquadrat|cut -c1)
  329.         zwei=$(echo $hexquadrat|cut -c2)
  330.         drei=$(echo $hexquadrat|cut -c3)
  331.         vier=$(echo $hexquadrat|cut -c4)
  332.         fuenf=$(echo $hexquadrat|cut -c5)
  333.         sechs=$(echo $hexquadrat|cut -c6)
  334.         sieben=$(echo $hexquadrat|cut -c7)
  335.         acht=$(echo $hexquadrat|cut -c8)
  336.  
  337.         #schreiben des Headers bzw. des kompletten Bmp-Hexdumps
  338.         if [[ $count = [1-3] ]]
  339.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  340. 00 00 $eins$zwei 00 00 00 $eins$zwei 00 00 00 01 00 18 00 00 00
  341. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  342. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  343.         fi
  344.  
  345.         if [[ $count = 4 ]]
  346.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  347. 00 00 $zwei$drei 0$eins 00 00 $zwei$drei 0$eins 00 00 01 00 18 00 00 00
  348. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  349. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  350.         fi
  351.  
  352.         if [[ $count = 5 ]]
  353.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  354. 00 00 $drei$vier $eins$zwei 00 00 $drei$vier $eins$zwei 00 00 01 00 18 00 00 00
  355. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  356. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  357.         fi
  358.  
  359.         if [[ $count = 6 ]]
  360.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  361. 00 00 $vier$fuenf $zwei$drei 0$eins 00 $vier$fuenf $zwei$drei 0$eins 00 01 00 18 00 00 00
  362. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  363. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  364.         fi
  365.  
  366.         if [[ $count = 7 ]]
  367.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  368. 00 00 $fuenf$sechs $drei$vier $eins$zwei 00 $fuenf$sechs $drei$vier $eins$zwei 00 01 00 18 00 00 00
  369. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  370. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  371.         fi
  372.  
  373.         if [[ $count = 8 ]]
  374.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  375. 00 00 $sechs$sieben $vier$fuenf $zwei$drei 0$eins $sechs$sieben $vier$fuenf $zwei$drei 0$eins 01 00 18 00 00 00
  376. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  377. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  378.         fi
  379.  
  380.         if [[ $count = 9 ]]
  381.             then    echo -e "42 4d 00 00 00 00 00 00 00 00 36 00 00 00 28 00
  382. 00 00 $sieben$acht $fuenf$sechs $drei$vier $eins$zwei $sieben$acht $fuenf$sechs $drei$vier $eins$zwei 01 00 18 00 00 00
  383. 00 00 10 00 00 00 13 0b 00 00 13 0b 00 00 00 00
  384. 00 00 00 00 00 00 $hexdump">/tmp/blabla.tmp
  385.         fi
  386.  
  387.         #umwandeln des Hexdumps in ASCII (Bmp erzeugen) und als Bild visualisieren
  388.         cat /tmp/blabla.tmp |cut -c-48|xxd -r -p>$file-square.bmp
  389.         rm /tmp/blabla.tmp /tmp/bloblo.tmp /tmp/dd.txt
  390.         notify-send "See"
  391.         eog $file-square.bmp
  392.         cp $file-square.bmp ~/Desktop
  393.                 clear
  394.                 tput bold
  395.                 tput cup 3 10
  396.                 echo -e "
  397.  
  398.        a copy of <your-PDF_as.bmp> lies on your Desktop...
  399.  
  400. Thank you
  401.  
  402. "
  403.     rm $file-square.bmp
  404.  
  405. else echo -e "\033[34m
  406.  
  407. OH SHIT! i was never been into this space...
  408.  
  409. Sorry, but if you want to define a new one,
  410. you have to open the door by yourself and modify -tmka-
  411.  
  412. -------------------
  413.  
  414. Remember:
  415.  
  416. tmka >> can only read:
  417.  
  418.        .txt and .pdf for your Textfiles
  419.  
  420.        .png .jpg .tif .gif .bmp for your Imagefiles
  421.  
  422. tmka >> cannot handle Videofiles or anything else
  423.  
  424.  
  425. \033[0m"
  426.  
  427. fi
Advertisement
Add Comment
Please, Sign In to add comment