Skip to content

Instantly share code, notes, and snippets.

@yoichitgy
Created March 17, 2015 05:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yoichitgy/0c7951c3b01005492b97 to your computer and use it in GitHub Desktop.
Save yoichitgy/0c7951c3b01005492b97 to your computer and use it in GitHub Desktop.
A script to generates iOS asset PNG images from a PSD file for @1x, @2x and @3x scales.
#!/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