Created
July 27, 2016 20:26
-
-
Save InsertNetan/451c2d53b88b5c76613fe6e7c4672514 to your computer and use it in GitHub Desktop.
a script for generating the right size images for the appStore assets
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
#!/bin/bash | |
set -e | |
SRC_FILE="$1" | |
DST_PATH="$2" | |
VERSION=1.0.0 | |
info() { | |
local green="\033[1;32m" | |
local normal="\033[0m" | |
echo -e "[${green}INFO${normal}] $1" | |
} | |
error() { | |
local red="\033[1;31m" | |
local normal="\033[0m" | |
echo -e "[${red}ERROR${normal}] $1" | |
} | |
usage() { | |
cat << EOF | |
VERSION: $VERSION | |
USAGE: | |
$0 srcfile dstpath | |
DESCRIPTION: | |
This script aim to generate iOS assets for the appstore easier and simply. | |
srcfile - The source png image. | |
dstpath - The destination path where the images generate to. | |
This script is depend on ImageMagick. So you must install ImageMagick first | |
You can use 'sudo brew install ImageMagick' to install it | |
EXAMPLE: | |
$0 1024.png ~/123 | |
EOF | |
} | |
# Check ImageMagick | |
command -v convert >/dev/null 2>&1 || { error >&2 "The ImageMagick is not installed. Please use brew to install it first."; exit -1; } | |
# Check param | |
if [ $# != 2 ];then | |
usage | |
exit -1 | |
fi | |
# Check dst path whether exist. | |
if [ ! -d "$DST_PATH" ];then | |
mkdir -p "$DST_PATH" | |
fi | |
info "Generate ${SRC_FILE%.*}_ipad.png.." | |
convert "$SRC_FILE" -resize 1536x2048! "$DST_PATH/${SRC_FILE%.*}_ipad.png" | |
info "Generate ${SRC_FILE%.*}_ipadPro.png.." | |
convert "$SRC_FILE" -resize 2048x2732! "$DST_PATH/${SRC_FILE%.*}_ipadPro.png" | |
info "Generate ${SRC_FILE%.*}_iPhone4.png.." | |
convert "$SRC_FILE" -resize 640x960! "$DST_PATH/${SRC_FILE%.*}_iPhone4.png" | |
info "Generate ${SRC_FILE%.*}_iPhone5.png.." | |
convert "$SRC_FILE" -resize 640x1036! "$DST_PATH/${SRC_FILE%.*}_iPhone5.png" | |
info "Generate ${SRC_FILE%.*}_iPhone6.png.." | |
convert "$SRC_FILE" -resize 750x1334! "$DST_PATH/${SRC_FILE%.*}_iPhone6.png" | |
info "Generate ${SRC_FILE%.*}_iPhone6Plus.png.." | |
convert "$SRC_FILE" -resize 1242x2208! "$DST_PATH/${SRC_FILE%.*}_iPhone6Plus.png" | |
info 'Generate Done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment