Last active
January 10, 2025 00:42
-
-
Save marcprux/f745cbde785c87f656cdd8c3c3656174 to your computer and use it in GitHub Desktop.
Script to convert a PDF or SVG into iOS and Android app icons for a Skip project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -ex | |
# This script should be executed in the root of a Skip project | |
# It will convert the specified image source (typically a PDF) | |
# into all the required icons for the Darwin/ and Android/ versions | |
# | |
# Prerequisite: `brew install imagemagick` | |
# | |
# e.g.: skip.iconconvert.sh Sources/Showcase/Resources/Module.xcassets/skiplogo.imageset/skiplogo.pdf | |
which magick &> /dev/null || (echo "$(basename $0): error: magick command not found (install imagemagick)"; exit 1) | |
if [ -z "$1" ]; then | |
echo "Usage: $(basename $0) SRC.pdf BGCOLOR" | |
exit 1 | |
fi | |
SRC=$1 | |
BGCOLOR=${2:-"white"} | |
convert() { | |
# Aetting the -density before the file name will help when rasterising | |
# svg images and preventing pixalation. | |
# It also (unintuitively) reduces the resulting .png file sizes. | |
magick +antialias -density 2000 "${SRC}" -background "${BGCOLOR}" -define png:exclude-chunks=date,time -strip -flatten -resize "${@}" | |
} | |
convert 48x48 Android/app/src/main/res/mipmap-mdpi/ic_launcher.png | |
convert 72x72 Android/app/src/main/res/mipmap-hdpi/ic_launcher.png | |
convert 192x192 Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | |
convert 144x144 Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png | |
convert 96x96 Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png | |
convert 40x40 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 40x40 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-20@2x~ipad.png | |
convert 60x60 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 20x20 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-20~ipad.png | |
convert 29x29 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-29.png | |
convert 58x58 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 58x58 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-29@2x~ipad.png | |
convert 87x87 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 29x29 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-29~ipad.png | |
convert 80x80 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 80x80 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-40@2x~ipad.png | |
convert 120x120 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 40x40 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-40~ipad.png | |
convert 167x167 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon-83.5@2x~ipad.png | |
convert 120x120 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 152x152 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon@2x~ipad.png | |
convert 180x180 Darwin/Assets.xcassets/AppIcon.appiconset/[email protected] | |
convert 1024x1024 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon~ios-marketing.png | |
convert 76x76 Darwin/Assets.xcassets/AppIcon.appiconset/AppIcon~ipad.png | |
# output the file sizes | |
du -skhc Android/app/src/main/res/*/*.png Darwin/Assets.xcassets/AppIcon.appiconset/*.png | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment