Skip to content
Permalink
Browse files

Nearly working - icons OK, launchImages not so much.

  • Loading branch information...
josephlord committed Dec 5, 2013
1 parent 70ad4e2 commit 28b9ee2b0065924a53e2a9dace4ad876aa8f6d90
Showing with 24 additions and 15 deletions.
  1. +1 −0 .gitignore
  2. +23 −15 convert.rb
  3. 0 output/.gitkeep
@@ -10,6 +10,7 @@ rdoc
spec/reports
test/tmp
test/version_tmp
output/*.png
tmp

# YARD artifacts
@@ -1,20 +1,20 @@
#!/usr/bin/env ruby

require 'pry'

# Original inspiration from:
# ruby -e '[58,120,29,40,80,76,152,1024].each { |x|
# `/Applications/Inkscape.app/Contents/Resources/bin/inkscape
# --export-png icon#{x}.png -w #{x} icon.svg` }'

inkscape_app = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape'
def inkscape_app
'/Applications/Inkscape.app/Contents/Resources/bin/inkscape'
end
input_file_name = 'test_files/test_file.svg'
output_folder = 'output'

#original_width = `#{inkscape_app} -z -C -W #{input_file_name}`

ios_icon_sizes = [58,120,29,40,80,76,152,1024]
launch_image_sizes = []
launch_image_sizes = [[640,960],[640,1160],[768,1024],[1536,2048],[1024,768],[2048,1536],[320,480],[768,1004],[1536,2008],[1024,748],[2048,1496]]

# <svg[^<>]*width="([\d\.]*)"[^<>]*>
def get_svg_size(file_name)
widthRegex = Regexp.new '<svg[^<>]*width="([\d\.]*)"[^<>]*>'
heightRegex = Regexp.new '<svg[^<>]*height="([\d\.]*)"[^<>]*>'
@@ -28,11 +28,9 @@ def get_svg_size(file_name)
return {height: height, width: width}
end

original_dimensions = get_svg_size(input_file_name)

puts "The original dimenstions are #{original_dimensions[:width]} by #{original_dimensions[:height]}"

def aspect_fit(width, height, original_width, original_height)
width = width.to_f
height = height.to_f
if width == original_width && height == original_height
return {x0: 0, y0: 0, x1: height, x2: width}
end
@@ -61,12 +59,11 @@ def aspect_fit(width, height, original_width, original_height)
end

def output_png(png_name,svg_name,width,height,background_colour=nil)
export_area_arg = ''
background_colour ||= '#ffffff'
original_dimensions = get_svg_size(file_name)
original_dimensions = get_svg_size(svg_name)
export_area = aspect_fit(width,height,original_dimensions[:width],original_dimensions[:height])
export_area_arg = "--export-area=#{export_area[:x0]}:#{export_area[:y0]}:#{export_area[:x1]}:#{export_area[:y1]}"
`inkscape_app --export-background=#{background_colour} #{export_area_arg} --export-png png_name -w #{width} #{svg_name}` }
`#{inkscape_app} --export-background=#{background_colour} #{export_area_arg} --export-png png_name -w #{width} #{svg_name}`
end

# Outputs a png of the name iconX.png where X is an item from the array
@@ -78,5 +75,16 @@ def output_square_icons(sizes=ios_icon_sizes,file_name=input_file_name,backgroun
export_area = aspect_fit(1,1,original_dimensions[:width],original_dimensions[:height])
export_area_arg = "--export-area=#{export_area[:x0]}:#{export_area[:y0]}:#{export_area[:x1]}:#{export_area[:y1]}"
end
sizes.each { |x| `inkscape_app --export-background=#{background_colour} #{export_area_arg} --export-png icon#{x}.png -w #{x} #{file_name}` }
end
sizes.each { |x| `#{inkscape_app} --export-background=#{background_colour} #{export_area_arg} --export-png icon#{x}.png -w #{x} #{file_name}` }
end

launch_image = 'test_files/test_file.svg'
icon_image = 'test_files/icon.svg'

launch_image_sizes.each do |size|
width = size[0]
height = size[1]
output_png "output/launch#{width}x#{height}.png", launch_image, width, height
end

output_square_icons ios_icon_sizes, icon_image
No changes.

0 comments on commit 28b9ee2

Please sign in to comment.
You can’t perform that action at this time.