Skip to content

Instantly share code, notes, and snippets.

@mogya
Created November 20, 2012 13:23
Show Gist options
  • Save mogya/4117915 to your computer and use it in GitHub Desktop.
Save mogya/4117915 to your computer and use it in GitHub Desktop.
create all graphics for iPhone and Android application using rmagick
require 'RMagick'
include Magick
BKCOLOR_SPLASH = '#0000FF'
BKCOLOR_ICON = '#0000FF'
def mkAppIcon(iconfile,size,bkColor='#000000')
canvas = Image.new(size,size){
self.background_color = bkColor
self.format = 'png'
}
icon = Magick::ImageList.new(iconfile)
icon.resize_to_fit!(size,size)
canvas.composite(icon, CenterGravity,OverCompositeOp)
end
Dir::mkdir('iphone') rescue nil
Dir::mkdir('android') rescue nil
mkAppIcon('icon.svg',57,BKCOLOR_ICON).write('iphone/Icon.png')
mkAppIcon('icon.svg',114,BKCOLOR_ICON).write('iphone/[email protected]')
mkAppIcon('icon.svg',72,BKCOLOR_ICON).write('iphone/Icon_72.png')
mkAppIcon('splash_screen.svg',512,BKCOLOR_SPLASH).write('iphone/ITunesArtwork')
mkAppIcon('icon.svg',128,BKCOLOR_ICON).write('android/appicon.png')
mkAppIcon('splash_screen.svg',512,BKCOLOR_SPLASH).write('android/appiconAndroid.png')
def mkSplash(file,width,height,bkColor='#000000')
canvas = Image.new(width,height){
self.background_color = bkColor
self.format = 'png'
}
icon = Magick::ImageList.new(file)
icon.resize_to_fit!(width,height)
canvas.composite(icon, CenterGravity,OverCompositeOp)
end
mkSplash('splash_screen.svg',320,480,BKCOLOR_SPLASH).write('iphone/Default.png')
mkSplash('splash_screen.svg',640,960,BKCOLOR_SPLASH).write('iphone/[email protected]')
mkSplash('splash_screen.svg',640,1136,BKCOLOR_SPLASH).write('iphone/[email protected]')
mkSplash('splash_screen.svg',768,1024,BKCOLOR_SPLASH).write('iphone/Default-Portrait.png')
mkSplash('splash_screen.svg',1024,768,BKCOLOR_SPLASH).write('iphone/Default-Landscape.png')
mkSplash('splash_screen.svg',320,480,BKCOLOR_SPLASH).write('android/Default.png')
mkSplash('splash_screen.svg',1024,500,BKCOLOR_SPLASH).write('android/marketTop.png')
mkSplash('icon.svg',180,120,BKCOLOR_ICON).write('android/promotion.png')
mkSplash('splash_screen.svg',320,480,BKCOLOR_SPLASH).write('android/marketTop.png')
Dir::mkdir('android/res-long-land-hdpi/') rescue nil
Dir::mkdir('android/res-long-land-ldpi/') rescue nil
Dir::mkdir('android/res-long-port-hdpi/') rescue nil
Dir::mkdir('android/res-long-port-ldpi/') rescue nil
Dir::mkdir('android/res-notlong-land-hdpi/') rescue nil
Dir::mkdir('android/res-notlong-land-ldpi/') rescue nil
Dir::mkdir('android/res-notlong-land-mdpi/') rescue nil
Dir::mkdir('android/res-notlong-port-hdpi/') rescue nil
Dir::mkdir('android/res-notlong-port-ldpi/') rescue nil
Dir::mkdir('android/res-notlong-port-mdpi/') rescue nil
mkSplash('splash_screen.svg',800,480,BKCOLOR_SPLASH).write('android/res-long-land-hdpi/Default.png')
mkSplash('splash_screen.svg',400,240,BKCOLOR_SPLASH).write('android/res-long-land-ldpi/Default.png')
mkSplash('splash_screen.svg',480,800,BKCOLOR_SPLASH).write('android/res-long-port-hdpi/Default.png')
mkSplash('splash_screen.svg',240,400,BKCOLOR_SPLASH).write('android/res-long-port-ldpi/Default.png')
mkSplash('splash_screen.svg',800,480,BKCOLOR_SPLASH).write('android/res-notlong-land-hdpi/Default.png')
mkSplash('splash_screen.svg',320,240,BKCOLOR_SPLASH).write('android/res-notlong-land-ldpi/Default.png')
mkSplash('splash_screen.svg',480,320,BKCOLOR_SPLASH).write('android/res-notlong-land-mdpi/Default.png')
mkSplash('splash_screen.svg',480,800,BKCOLOR_SPLASH).write('android/res-notlong-port-hdpi/Default.png')
mkSplash('splash_screen.svg',240,320,BKCOLOR_SPLASH).write('android/res-notlong-port-ldpi/Default.png')
mkSplash('splash_screen.svg',320,480,BKCOLOR_SPLASH).write('android/res-notlong-port-mdpi/Default.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment