Guest User

Untitled

a guest
Jan 21st, 2018
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. for f in *.png
  2. do
  3. # Process to get File Name & 2x, 3x file names
  4. xNAME=`echo "$f" | cut -d'.' -f1`
  5. cp "$f" "$xNAME@3x.png"
  6. cp "$f" "$xNAME@2x.png"
  7.  
  8. # Set proper resolution to original file
  9. sips -s dpiHeight 72.0 -s dpiWidth 72.0 "$f"
  10.  
  11. # Get Width of original file
  12. xWIDTH=`sips -g pixelWidth "$f" | cut -d':' -f 2 | tail -1 | cut -d' ' -f 2`
  13.  
  14. # Get Height of original file
  15. xHEIGHT=`sips -g pixelHeight "$f" | cut -d':' -f 2 | tail -1 | cut -d' ' -f 2`
  16.  
  17. # Variables for 1x
  18. xWIDTH1=`expr $xWIDTH / 3`
  19. xHEIGHT1=`expr $xHEIGHT / 3`
  20.  
  21. # Variables for 2x
  22. xWIDTH2=`expr $xWIDTH1 \* 2`
  23. xHEIGHT2=`expr $xHEIGHT1 \* 2`
  24.  
  25. # Applying size to all three images
  26. sips -z "$xHEIGHT1" "$xWIDTH1" "$f"
  27. sips -z "$xHEIGHT2" "$xWIDTH2" "$xNAME@2x.png"
  28.  
  29. # Creating Asset folder & moving images into asset folder
  30. mkdir "$xNAME.imageset"
  31. mv "$f" "$xNAME.imageset/"
  32. mv "$xNAME@2x.png" "$xNAME.imageset/"
  33. mv "$xNAME@3x.png" "$xNAME.imageset/"
  34.  
  35. echo "{ \"images\" : [ { \"idiom\" : \"universal\", \"filename\" : \"$f\", \"scale\" : \"1x\" }, { \"idiom\" : \"universal\", \"filename\" : \"$xNAME@2x.png\", \"scale\" : \"2x\" }, { \"idiom\" : \"universal\", \"filename\" : \"$xNAME@3x.png\", \"scale\" : \"3x\" } ], \"info\" : { \"version\" : 1, \"author\" : \"xcode\" } }" > Contents.json
  36.  
  37. mv Contents.json "$xNAME.imageset/"
  38.  
  39. done
Add Comment
Please, Sign In to add comment