-
-
Save embassem/ce8d0ebfcb1924799c1f287f7c712494 to your computer and use it in GitHub Desktop.
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 | |
# | |
# genassetimages.sh | |
# Generates iOS asset PNG images from a PSD file for @1x, @2x and @3x scales. | |
# ImageMagick is used to resize the images. | |
# | |
# settings ========== | |
outputDir="image_assets" | |
assetSuffixes=(".png" "@2x.png" "@3x.png") | |
# ==================== | |
if [ $# -eq 0 ]; then | |
echo "Usage: genassetimages.sh psd_path ..." | |
echo " psd_path has a scale suffix like 'icon@6x.psd'." | |
exit 1 | |
fi | |
mkdir -p $outputDir | |
for arg in $@ | |
do | |
sourceNameWithoutExt="${arg%.*}" | |
sourcePngPath=$outputDir"/"$sourceNameWithoutExt".png" | |
baseName="${arg%@*}" | |
scaleString="${arg##*@}" | |
sourceScale="${scaleString%%x.*}" | |
convert $arg"[0]" $sourcePngPath | |
sourceWidth=`identify -format "%w" $sourcePngPath` | |
for (( i = 0; i < ${#assetSuffixes[@]}; ++i )) | |
do | |
scale=`expr $i + 1` | |
width=`expr $sourceWidth \* $scale / $sourceScale` | |
assetSuffix=${assetSuffixes[$i]} | |
assetPath=$outputDir"/"$baseName$assetSuffix | |
echo ${assetPath} | |
convert -resize ${width}x -unsharp 2x1.4+0.5+0 $sourcePngPath $assetPath | |
done | |
rm $sourcePngPath | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment