metalx1000

Image to Emoji Squares

Apr 19th, 2022 (edited)
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2022  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. if [[ $# < 1 ]];
  21. then
  22.   echo "Input Image Needed"
  23.   echo "Example: $0 hello.png"
  24.   exit 1
  25. fi
  26.  
  27. #convert image to text with a value of either black or white
  28. txt="$(convert "$1"  -threshold 50% txt:-)"
  29.  
  30. #get count of how many pixels are in each row
  31. count="$(echo "$txt"|head -n1|cut -d\: -f2|cut -d\, -f1|awk '{print $1}')"
  32.  
  33. #replace all pixels with squares
  34. echo "$txt"|grep -v '^#'|awk '{print $4}'|sed 's/white/⬜/g;s/black/⬛/g'|tr -d "\n"|sed -e "s/.\{$count\}/&\n/g"
  35.  
Add Comment
Please, Sign In to add comment