Created
February 20, 2015 22:21
-
-
Save vitovalov/6f98510f24a92f6f02a0 to your computer and use it in GitHub Desktop.
Resize to a given size maintaining proportions and automatically generate all android resource directories
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
# Author: @vitovalov | |
# Description: Resize to a given size and automatically generate all android resource directories | |
# Usage: sh rescale_for_android.sh <dp size (mdpi)> <source path to original images> <output path for results>(optional) | |
if [ "$#" -le 1 ]; then | |
echo "\nUsage: sh rescale_for_android.sh <dp size (mdpi)> <source path to original images> <output path for results>(optional)\n" | |
exit 1 | |
fi | |
mdpisize=$1 | |
hdpisize=$(echo "$mdpisize * 1.5" | bc -l) | |
xhdpisize="$((mdpisize * 2))" | |
xxhdpisize="$((mdpisize * 3))" | |
sourceDir=$2 | |
if [ "$#" -eq 3 ]; then | |
outDir=$3 | |
else | |
echo "Warning: output directory not specified. Source dir will be used to create drawable directories" | |
outDir=$sourceDir | |
fi | |
# clean old directories | |
rm -rf $outDir/drawable-mdpi | |
rm -rf $outDir/drawable-hdpi | |
rm -rf $outDir/drawable-xhdpi | |
rm -rf $outDir/drawable-xxhdpi | |
# create new directories | |
mkdir $outDir/drawable-mdpi | |
mkdir $outDir/drawable-hdpi | |
mkdir $outDir/drawable-xhdpi | |
mkdir $outDir/drawable-xxhdpi | |
for f in $sourceDir/*.{jpg,jpeg,png}; | |
do | |
echo "resizing ${f##*/} to size $mdpisize dpi maintaining proportions" | |
sips -Z $mdpisize $f --out $outDir/drawable-mdpi > /dev/null 2>&1 | |
echo "resizing ${f##*/} to size $hdpisize dpi maintaining proportions" | |
sips -Z $hdpisize $f --out $outDir/drawable-hdpi > /dev/null 2>&1 | |
echo "resizing ${f##*/} to size $xhdpisize dpi maintaining proportions" | |
sips -Z $xhdpisize $f --out $outDir/drawable-xhdpi > /dev/null 2>&1 | |
echo "resizing ${f##*/} to size $xxhdpisize dpi maintaining proportions" | |
sips -Z $xxhdpisize $f --out $outDir/drawable-xxhdpi > /dev/null 2>&1 | |
done | |
# "drawable-mdpi" => 1.0, | |
# "drawable-hdpi" => 1.5, | |
# "drawable-xhdpi" => 2.0, | |
# "drawable-xxhdpi" => 3.0, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment