Created
August 25, 2016 13:49
-
-
Save ProGM/9f5aa77e00ab6a0d4f87f61738b09577 to your computer and use it in GitHub Desktop.
Prepare and resize images for Appcelerator using imagemagick
This file contains hidden or 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
#!/usr/bin/env bash | |
origin_raw_folder="raw_images" | |
rm -rf images | |
mkdir -p images/iphone | |
mkdir -p images/android/res-hdpi | |
mkdir -p images/android/res-hdpi | |
mkdir -p images/android/res-xhdpi | |
mkdir -p images/android/res-xxhdpi | |
resize_image() { | |
file=$1 | |
folder=$2 | |
suffix=$3 | |
percent=$4 | |
pathname=$(dirname "$file") | |
filename=$(basename "$file") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
destination="${pathname/$origin_raw_folder/$folder}" | |
echo "Resizing $file by $percent to $destination/$filename$suffix.$extension" | |
convert $file -filter lanczos -unsharp 1.5x1+0.7+0.02 -resize $percent "$destination/$filename$suffix.$extension" | |
} | |
move_image() { | |
file=$1 | |
folder=$2 | |
suffix=$3 | |
pathname=$(dirname "$file") | |
filename=$(basename "$file") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
destination="${pathname/$origin_raw_folder/$folder}" | |
echo "Copying $file to $destination/$filename$suffix.$extension" | |
cp "$file" "$destination/$filename$suffix.$extension" | |
} | |
for file in `find $origin_raw_folder -type f`; do | |
move_image $file "images/iphone" "@3x" | |
move_image $file "images/android/res-xxhdpi" | |
resize_image $file "images/iphone" "@2x" "66.66666666666667%" | |
resize_image $file "images/android/res-xhdpi" "" "66.66666666666667%" | |
resize_image $file "images/android/res-hdpi" "" "50%" | |
resize_image $file "images" "" "33.33333333333333%" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment