Skip to content

Instantly share code, notes, and snippets.

@ProGM
Created August 25, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProGM/9f5aa77e00ab6a0d4f87f61738b09577 to your computer and use it in GitHub Desktop.
Save ProGM/9f5aa77e00ab6a0d4f87f61738b09577 to your computer and use it in GitHub Desktop.
Prepare and resize images for Appcelerator using imagemagick
#!/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