update retina-scale and scale-ios-app-icons
This commit is contained in:
parent
bfee5916f7
commit
810e460a15
2 changed files with 34 additions and 24 deletions
53
retina-scale
53
retina-scale
|
|
@ -4,41 +4,50 @@ SCALES = [1, 2, 3]
|
||||||
|
|
||||||
def usage
|
def usage
|
||||||
name = File.basename(__FILE__)
|
name = File.basename(__FILE__)
|
||||||
puts "Usage: #{name} <size> <input-image> <output-directory>"
|
puts "Usage: #{name} <input-image> <output-directory> <output-filename-prefix> <width> <height>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_all_scales(size, in_file, out_dir)
|
def scale_retina(width, height, scale, in_file, out_dir, prefix)
|
||||||
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" : ''
|
file_scale = scale > 1 ? "@#{scale}x" : ''
|
||||||
ext = "_#{points}#{file_scale}.png"
|
filename = "#{prefix}#{file_scale}.png"
|
||||||
filename = File.basename(in_file).sub(/\.\w+$/, ext)
|
|
||||||
size = points * scale
|
|
||||||
out_file = File.join(out_dir, filename)
|
out_file = File.join(out_dir, filename)
|
||||||
puts "> convert '#{in_file}' -scale #{size}x#{size} '#{out_file}'"
|
puts "> convert '#{in_file}' -scale #{width * scale}x#{height * scale} '#{out_file}'"
|
||||||
output = `convert '#{in_file}' -scale #{size}x#{size} '#{out_file}'`.strip
|
output = `convert '#{in_file}' -scale #{width * scale}x#{height * scale} '#{out_file}'`.strip
|
||||||
puts output if output.length > 0
|
puts output if output.length > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
raw_size, in_file, out_dir = ARGV
|
def image_dimensions(path)
|
||||||
size = raw_size.to_f
|
`identify '#{path}'`.split[2].split('x').map(&:to_i)
|
||||||
unless size > 0
|
|
||||||
puts "Invalid size: #{raw_size.inspect}"
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
in_file, out_dir, prefix, raw_width, raw_height = ARGV
|
||||||
unless File.exist?(in_file)
|
unless File.exist?(in_file)
|
||||||
puts "Input image not found: #{in_file}"
|
puts "Input image not found: #{in_file}"
|
||||||
usage
|
usage
|
||||||
exit 2
|
exit 1
|
||||||
end
|
end
|
||||||
unless File.directory?(out_dir)
|
unless File.directory?(out_dir)
|
||||||
puts "Output directory not found: #{out_dir}"
|
puts "Output directory not found: #{out_dir}"
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 2
|
||||||
|
end
|
||||||
|
unless prefix && prefix.strip.length > 0
|
||||||
|
puts "Missing output filename prefix"
|
||||||
|
usage
|
||||||
|
exit 3
|
||||||
|
end
|
||||||
|
if raw_width && raw_height
|
||||||
|
width = raw_width.to_i
|
||||||
|
height = raw_height.to_i
|
||||||
|
else
|
||||||
|
width, height = image_dimensions(in_file).map { |x| x / 3 }
|
||||||
|
end
|
||||||
|
unless width > 0 && height > 0
|
||||||
|
puts "Invalid dimensions: #{raw_width.inspect} #{raw_height.inspect}"
|
||||||
|
usage
|
||||||
|
exit 4
|
||||||
|
end
|
||||||
|
|
||||||
|
SCALES.each do |scale|
|
||||||
|
scale_retina(width, height, scale, in_file, out_dir, prefix)
|
||||||
end
|
end
|
||||||
generate_all_scales(size, in_file, out_dir)
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ if [[ ! -d "$OUT_DIR" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for SIZE in 29 40 60 76 83.5; do
|
for SIZE in 29 40 60 76 83.5; do
|
||||||
echo "* Generating app icons at $SIZE points"
|
PREFIX="${IN_FILE%.png}_$SIZE"
|
||||||
retina-scale $SIZE "$IN_FILE" "$OUT_DIR"
|
echo "* Generating app icons at $SIZE points with filename prefix $PREFIX"
|
||||||
|
retina-scale "$IN_FILE" "$OUT_DIR" "$PREFIX" $SIZE $SIZE
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue