images_to_hex.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/bash
  2. # Converts every image *.png to *.txt as an ASCII hex representation of the image.
  3. #
  4. # This script simply runs image_to_code.py on each of the folders containing
  5. # our images and writes the hex of each image to a text file. Instead of updating
  6. # the original script, I left it to be generic as it was originally intended
  7. # in case someone else finds it useful. The original python script outputs
  8. # header and implementation files, which this script removes after it is run.
  9. #
  10. # Run this command to remove the hex files: find . -type f -name "*.txt" | xargs rm
  11. #
  12. # Usage: ./images_to_hex.sh [one or more folders in a quoted string]
  13. # Examples:
  14. # bash images_to_hex.sh
  15. # bash images_to_hex.sh toolbar
  16. # bash images_to_hex.sh "toolbar filetypes"
  17. #
  18. if [[ $1 ]]; then
  19. imageFolders="$1"
  20. else
  21. imageFolders="filetypes range-slider toolbar misc"
  22. fi
  23. for dir in $imageFolders; do
  24. rm $dir/*.txt
  25. for image in `ls $dir`; do
  26. name=`basename $image .png`
  27. outfile=$dir/$name.txt
  28. echo "Output file: $outfile"
  29. ./image_to_code.py -i $dir/$image -c $name > "$outfile"
  30. done
  31. done
  32. rm -rf *PNG.[hm]