Advertisement
metalx1000

Creates Game Sprite Sheet Grid from Sprite Atlas Image

Nov 16th, 2020 (edited)
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.33 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2020  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. original="$1"
  21. name="$(echo "$original"|cut -d\. -f1)"
  22. tmp="$PWD/${name}_tmp"
  23.  
  24. function error(){
  25.   echo "==ERROR=="
  26.   echo "$*"
  27.   exit 1
  28. }
  29.  
  30. echo "Creating tmp directories..."
  31. mkdir -p $tmp/{0,1} || error "Unable to create $tmp"
  32.  
  33. echo "Splitting Sprite $name Vertically..."
  34. ./divide_vert "$original" $tmp/0/output-$(date +%s).png
  35.  
  36. echo "Rotating and Splitting Sprite Horizontally"
  37. for i in $tmp/0/*.png;
  38. do
  39.   echo "$i"
  40.   convert $i -rotate 90 $i
  41.   ./divide_vert "$i" $tmp/1/output-$(date +%s).png
  42. done
  43.  
  44. #This is suppose to remove blank images, but didn't work very well
  45. for i in $tmp/1/*.png
  46. do
  47.    #check if image is blank
  48.    blank="$(identify -format "%[opaque] %[fx:mean] %[fx:standard_deviation]" $i|awk '{print $2}')"
  49.    if [ "$blank" = "0" ]
  50.    then
  51.      echo "$i is blank and will be removed"
  52.      rm "$i"
  53. #   else
  54. #     echo "Rotating $i"
  55. #     convert $i -rotate -90 $i
  56.    fi
  57. done
  58.  
  59. echo "Removing small images..."
  60. find pun_tmp/1/ -name "*.png" -type 'f' -size -2k -delete
  61.  
  62. #echo "Rotating $i"
  63. #convert $i -rotate -90 $i
  64.  
  65. echo "Calculating Largest Side..."
  66. size="$(identify $tmp/1/*.png|awk '{print $3}'|grep 'x'|tr 'x' '\n'|sort -ug|tail -n1)"
  67.  
  68. echo "Creating frames at ${size}x${size}"
  69. for i in $tmp/1/*.png;
  70. do
  71.   echo $i;
  72.   convert $i -background none -gravity center -extent ${size}x${size} $i;
  73. done
  74.  
  75. echo "Combining final sprite sheet ${name}_sheet.png..."
  76. montage $tmp/1/*.png -rotate -90 -geometry ${size}x${size} -background none ${name}_sheet.png
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement