Skip to content

Instantly share code, notes, and snippets.

@denvazh
Created February 22, 2015 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denvazh/ee97e7cd57a9d0e020bf to your computer and use it in GitHub Desktop.
Save denvazh/ee97e7cd57a9d0e020bf to your computer and use it in GitHub Desktop.
Generate ios icon settings for cordova.xml

How to use

This script assumes cordova application uses app/res/icons/ios directory for icon assets.

  • Install appicon_generate gem using bundler (refer to this)
    • Put gen_xml.rb in the same directry with Gemfile
  • Use appicon_generate to generate icons for ios
  • Run ./gen_xml.rb to generate related xml tags

Sample output:

<icon src="app/res/icons/ios/Icon-40.png" width="40" height="40" />
<icon src="app/res/icons/ios/Icon-40@2x.png" width="80" height="80" />
<icon src="app/res/icons/ios/Icon-40@3x.png" width="120" height="120" />
<icon src="app/res/icons/ios/Icon-60.png" width="60" height="60" />
<icon src="app/res/icons/ios/Icon-60@2x.png" width="120" height="120" />
<icon src="app/res/icons/ios/Icon-60@3x.png" width="180" height="180" />
<icon src="app/res/icons/ios/Icon-72.png" width="72" height="72" />
<icon src="app/res/icons/ios/Icon-72@2x.png" width="144" height="144" />
<icon src="app/res/icons/ios/Icon-76.png" width="76" height="76" />
<icon src="app/res/icons/ios/Icon-76@2x.png" width="152" height="152" />
<icon src="app/res/icons/ios/Icon-Small-50.png" width="50" height="50" />
<icon src="app/res/icons/ios/Icon-Small-50@2x.png" width="100" height="100" />
<icon src="app/res/icons/ios/Icon-Small.png" width="29" height="29" />
<icon src="app/res/icons/ios/Icon-Small@2x.png" width="58" height="58" />
<icon src="app/res/icons/ios/Icon-Small@3x.png" width="87" height="87" />
<icon src="app/res/icons/ios/Icon.png" width="57" height="57" />
<icon src="app/res/icons/ios/Icon@2x.png" width="114" height="114" />
#!/usr/bin/env ruby
require 'bundler/setup'
require 'rmagick'
dir = 'icons/ios'
icons=Dir.glob(File.join(dir, 'Icon*.png'))
settings = icons.map do |icon|
filename = File.basename(icon)
img = Magick::Image::ping(icon).first
width, height = img.columns, img.rows
entry = sprintf('<icon src="%s" width="%s" height="%s" />',
File.join('app/res/icons/ios',filename),
width,
height
)
end
puts settings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment