Created
October 20, 2021 20:52
-
-
Save chrissearle/9e96103b47b6fb98a5fed6aff6d6afb8 to your computer and use it in GitHub Desktop.
Create xcassets from three directories of PNG images - 1x, 2x and 3x
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/zsh | |
# Assumes you start with three directories of images in png format with the same name - 1x, 2x and 3x | |
# Call with four params | |
# zip_directories_to_xcassets.zsh name_of_asset_file directory_of_1x_pngs directory_of_2x_pngs directory_of_3x_pngs | |
ASSETS_DIR=$1.xcassets | |
D1=$2 | |
D2=$3 | |
D3=$4 | |
mkdir -p $ASSETS_DIR | |
cat <<EOT > $ASSETS_DIR/Contents.json | |
{ | |
"info" : { | |
"author" : "xcode", | |
"version" : 1 | |
} | |
} | |
EOT | |
for F in `ls $D1`; do | |
ROOT_NAME=${F%%.png} | |
mkdir -p $ASSETS_DIR/$ROOT_NAME.imageset | |
cat <<EOT > $ASSETS_DIR/$ROOT_NAME.imageset/Contents.json | |
{ | |
"images" : [ | |
{ | |
"filename" : "$ROOT_NAME.png", | |
"idiom" : "universal", | |
"scale" : "1x" | |
}, | |
{ | |
"filename" : "$ROOT_NAME-2.png", | |
"idiom" : "universal", | |
"scale" : "2x" | |
}, | |
{ | |
"filename" : "$ROOT_NAME-3.png", | |
"idiom" : "universal", | |
"scale" : "3x" | |
} | |
], | |
"info" : { | |
"author" : "xcode", | |
"version" : 1 | |
} | |
} | |
EOT | |
cp $D1/$ROOT_NAME.png $ASSETS_DIR/$ROOT_NAME.imageset/$ROOT_NAME.png | |
cp $D2/$ROOT_NAME.png $ASSETS_DIR/$ROOT_NAME.imageset/$ROOT_NAME-2.png | |
cp $D3/$ROOT_NAME.png $ASSETS_DIR/$ROOT_NAME.imageset/$ROOT_NAME-3.png | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment