Last active
September 26, 2024 11:30
-
-
Save sag333ar/bf55ac27c6ffa5fd2ee72fd4f5b79fe9 to your computer and use it in GitHub Desktop.
Generate 1x 2x 3x images from supplied 3x assets. Following shell-script can be used for iOS Asset catalogue.
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
for f in *.png | |
do | |
# Process to get File Name & 2x, 3x file names | |
xNAME=`echo "$f" | cut -d'.' -f1` | |
cp "$f" "[email protected]" | |
cp "$f" "[email protected]" | |
# Set proper resolution to original file | |
sips -s dpiHeight 72.0 -s dpiWidth 72.0 "$f" | |
# Get Width of original file | |
xWIDTH=`sips -g pixelWidth "$f" | cut -d':' -f 2 | tail -1 | cut -d' ' -f 2` | |
# Get Height of original file | |
xHEIGHT=`sips -g pixelHeight "$f" | cut -d':' -f 2 | tail -1 | cut -d' ' -f 2` | |
# Variables for 1x | |
xWIDTH1=`expr $xWIDTH / 3` | |
xHEIGHT1=`expr $xHEIGHT / 3` | |
# Variables for 2x | |
xWIDTH2=`expr $xWIDTH1 \* 2` | |
xHEIGHT2=`expr $xHEIGHT1 \* 2` | |
# Applying size to all three images | |
sips -z "$xHEIGHT1" "$xWIDTH1" "$f" | |
sips -z "$xHEIGHT2" "$xWIDTH2" "[email protected]" | |
# Creating Asset folder & moving images into asset folder | |
mkdir "$xNAME.imageset" | |
mv "$f" "$xNAME.imageset/" | |
mv "[email protected]" "$xNAME.imageset/" | |
mv "[email protected]" "$xNAME.imageset/" | |
echo "{ \"images\" : [ { \"idiom\" : \"universal\", \"filename\" : \"$f\", \"scale\" : \"1x\" }, { \"idiom\" : \"universal\", \"filename\" : \"[email protected]\", \"scale\" : \"2x\" }, { \"idiom\" : \"universal\", \"filename\" : \"[email protected]\", \"scale\" : \"3x\" } ], \"info\" : { \"version\" : 1, \"author\" : \"xcode\" } }" > Contents.json | |
mv Contents.json "$xNAME.imageset/" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment