add scripts to resize images and app icons for iOS

This commit is contained in:
Sami Samhuri 2015-07-07 11:39:55 -07:00
parent e371a21240
commit ed1fe9602f
2 changed files with 68 additions and 0 deletions

44
retina-scale Executable file
View file

@ -0,0 +1,44 @@
#!/usr/bin/ruby -w
SCALES = [1, 2, 3]
def usage
name = File.basename(__FILE__)
puts "Usage: #{name} <size> <input-image> <output-directory>"
end
def generate_all_scales(size, in_file, out_dir)
SCALES.each do |scale|
scale_retina(size, scale, in_file, out_dir)
end
end
def scale_retina(points, scale, in_file, out_dir)
file_scale = scale > 1 ? "@#{scale}x" : ''
ext = "_#{points}#{file_scale}.png"
filename = File.basename(in_file).sub(/\.\w+$/, ext)
size = points * scale
out_file = File.join(out_dir, filename)
puts "> convert '#{in_file}' -scale #{size}x#{size} '#{out_file}'"
output = `convert '#{in_file}' -scale #{size}x#{size} '#{out_file}'`.strip
puts output if output.length > 0
end
raw_size, in_file, out_dir = ARGV
size = raw_size.to_i
unless size > 0
puts "Invalid size: #{raw_size.inspect}"
usage
exit 1
end
unless File.exist?(in_file)
puts "Input image not found: #{in_file}"
usage
exit 2
end
unless File.directory?(out_dir)
puts "Output directory not found: #{out_dir}"
usage
exit 1
end
generate_all_scales(size, in_file, out_dir)

24
scale-ios-app-icons Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh
function usage() {
echo "Usage: $0 <source-icon> <output-directory>"
}
IN_FILE="$1"
OUT_DIR="$2"
if [[ ! -r "$IN_FILE" ]]; then
echo "Source icon not found: $IN_FILE"
usage
exit 1
fi
if [[ ! -d "$OUT_DIR" ]]; then
echo "Output directory not found: $OUT_DIR"
usage
exit 2
fi
for SIZE in 29 40 60 76; do
echo "* Generating app icons at $SIZE points"
retina-scale $SIZE "$IN_FILE" "$OUT_DIR"
done