icns_generator.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # icns_generator.sh GNU GPLv3 License
  3. # Run this script when a new logo is made and the svg file inside.
  4. # You should install Imagemagick to make the conversions: $brew install imagemagick
  5. # Change working dir to where this script is located.
  6. cd "${0%/*}"
  7. if [ -z $1 ]; then
  8. echo "icns_generator.sh GNU GPLv3 License"
  9. echo "Run this script when a new logo is made and the svg file inside."
  10. echo ""
  11. echo "Syntax: ./icns_generator <input.svg>"
  12. echo ""
  13. echo "Don't forget to install imagemagick: "
  14. echo "$ brew install imagemagick"
  15. exit 0
  16. fi
  17. # Error Handling Stuff:
  18. ## Check command availability
  19. check_command() {
  20. if ! command -v "$1" &> /dev/null; then
  21. read -s -n 1 -p "Error: '$1' command not found. Please install $2."
  22. exit 1
  23. fi
  24. }
  25. ## Convert image with error handling
  26. convert_image() {
  27. convert -background none -resize "$2" "$1" "$3" || {
  28. read -s -n 1 -p "Error: Conversion failed for $1"
  29. exit 1
  30. }
  31. }
  32. # Check required commands
  33. check_command "convert" "ImageMagick"
  34. check_command "iconutil" "macOS"
  35. # Create the iconset directory
  36. mkdir suyu.iconset || {
  37. read -s -n 1 -p "Error: Unable to create suyu.iconset directory."
  38. exit 1
  39. }
  40. # Convert images
  41. convert_image "$1" 16x16 suyu.iconset/icon_16x16.png
  42. convert_image "$1" 32x32 suyu.iconset/icon_16x16@2x.png
  43. convert_image "$1" 32x32 suyu.iconset/icon_32x32.png
  44. convert_image "$1" 64x64 suyu.iconset/icon_32x32@2x.png
  45. convert_image "$1" 128x128 suyu.iconset/icon_128x128.png
  46. convert_image "$1" 256x256 suyu.iconset/icon_256x256.png
  47. convert_image "$1" 256x256 suyu.iconset/icon_128x128@2x.png
  48. convert_image "$1" 512x512 suyu.iconset/icon_256x256@2x.png
  49. convert_image "$1" 512x512 suyu.iconset/icon_512x512.png
  50. convert_image "$1" 1024x1024 suyu.iconset/icon_512x512@2x.png
  51. # Create the ICNS file
  52. iconutil -c icns suyu.iconset || {
  53. read -s -n 1 -p "Error: Failed to create ICNS file."
  54. exit 1
  55. }
  56. # Remove the temporary iconset directory
  57. rm -rf suyu.iconset || {
  58. read -s -n 1 -p "Error: Unable to remove suyu.iconset directory."
  59. exit 1
  60. }
  61. echo -s -n 1 -p "Icon generation completed successfully."
  62. echo ""