From 810e460a15f5e9473f69774bfb696c6a8d8d88c8 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 13 Feb 2016 13:42:18 -0800 Subject: [PATCH] update retina-scale and scale-ios-app-icons --- retina-scale | 53 ++++++++++++++++++++++++++------------------- scale-ios-app-icons | 5 +++-- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/retina-scale b/retina-scale index d392bf2..7405976 100755 --- a/retina-scale +++ b/retina-scale @@ -4,41 +4,50 @@ SCALES = [1, 2, 3] def usage name = File.basename(__FILE__) - puts "Usage: #{name} " + puts "Usage: #{name} " 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) +def scale_retina(width, height, scale, in_file, out_dir, prefix) file_scale = scale > 1 ? "@#{scale}x" : '' - ext = "_#{points}#{file_scale}.png" - filename = File.basename(in_file).sub(/\.\w+$/, ext) - size = points * scale + filename = "#{prefix}#{file_scale}.png" 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 "> convert '#{in_file}' -scale #{width * scale}x#{height * scale} '#{out_file}'" + output = `convert '#{in_file}' -scale #{width * scale}x#{height * scale} '#{out_file}'`.strip puts output if output.length > 0 end -raw_size, in_file, out_dir = ARGV -size = raw_size.to_f -unless size > 0 - puts "Invalid size: #{raw_size.inspect}" - usage - exit 1 +def image_dimensions(path) + `identify '#{path}'`.split[2].split('x').map(&:to_i) end + +in_file, out_dir, prefix, raw_width, raw_height = ARGV unless File.exist?(in_file) puts "Input image not found: #{in_file}" usage - exit 2 + exit 1 end unless File.directory?(out_dir) puts "Output directory not found: #{out_dir}" 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 -generate_all_scales(size, in_file, out_dir) diff --git a/scale-ios-app-icons b/scale-ios-app-icons index d97ca19..697ec95 100755 --- a/scale-ios-app-icons +++ b/scale-ios-app-icons @@ -20,6 +20,7 @@ if [[ ! -d "$OUT_DIR" ]]; then fi for SIZE in 29 40 60 76 83.5; do - echo "* Generating app icons at $SIZE points" - retina-scale $SIZE "$IN_FILE" "$OUT_DIR" + PREFIX="${IN_FILE%.png}_$SIZE" + echo "* Generating app icons at $SIZE points with filename prefix $PREFIX" + retina-scale "$IN_FILE" "$OUT_DIR" "$PREFIX" $SIZE $SIZE done