Class: Rubyapple::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyapple.rb

Instance Method Summary collapse

Constructor Details

#initializeMain

Returns a new instance of Main.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubyapple.rb', line 7

def initialize
  args = ARGV[0..-1]

  unless !args[1]
    image = Magick::Image.read(args[1])[0].strip!
  end

  case
  when args[0] == 'help'
    puts "rubyapple version #{Rubyapple::VERSION}"
    puts ""
    puts "rubyapple gen-apple-touch imagename.png"
    puts " -- outputs apple-touch-icon-* files to apple_images/*"
    puts ""
    puts "rubyapple gen-drawables imagename.png"
    puts " -- outputs drawable-*         files to drawable_images/*"
    puts ""
    puts "rubyapple gen-all imagename.png"
    puts " -- outputs all types         files to *_images/*"
    puts ""
  when args[0] == 'gen-apple-touch'
    puts "initializing.. gen-apple-touch"
    generate_apples(image)
  when args[0] == 'gen-drawables'
    puts "initializing.. gen-drawables"
    generate_drawables(image)
  when args[0] == 'gen-all'
    puts "initializing.. generation of all types.."
    generate_apples(image)
    generate_drawables(image)
  when args[0] == 'version' || args[0] == '-v'
    puts "Current rubyapple version: #{Rubyapple::VERSION}"
  else
    puts "-"
    puts "did you forget something?"
    puts "-"
    puts "use 'rubyapple help' for more information"
  end

  unless args[0]
    puts "correct syntax:"
    puts " rubyapple type image.png"
    puts "use 'rubyapple help' for more information"
  end

end

Instance Method Details

#create_folder(folname) ⇒ Object



102
103
104
# File 'lib/rubyapple.rb', line 102

def create_folder(folname)
  FileUtils.mkdir_p(folname)
end

#generate_apples(img) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rubyapple.rb', line 54

def generate_apples(img)
  if !File.directory?('apple_images/')
    puts "Creating folder apple_images..."
    create_folder('apple_images')
  end
  # apple-touch-icon-sizes.png
  sizes = [16, 32, 57, 70, 76, 96, 114, 120, 144, 152, 167, 180, 270, 310]

  temp = img

  puts "Generating pictures.. apple-touch-icon-types"
  @numi = 0
  (0..sizes.length).each do |x|
    fsizes = "#{sizes[@numi]}x#{sizes[@numi]}"
    fname = "apple-touch-icon-#{fsizes}.png"
    fname2 = "apple-touch-icon-#{fsizes}-precomposed.png"
    path = "apple_images/"
    temp.resize_to_fill(sizes[@numi].to_i, sizes[@numi].to_i).write(path + "#{fname}")
    temp.resize_to_fill(sizes[@numi].to_i, sizes[@numi].to_i).write(path + "#{fname2}")
    if @numi < sizes.length - 1
      @numi += 1
    end
  end
  puts "Done!"
end

#generate_drawables(img) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rubyapple.rb', line 80

def generate_drawables(img)
  if !File.directory?('drawable_images/')
    puts "Creating folder drawable_images..."
    create_folder('drawable_images')
  end

  temp = img

  path = "drawable_images/"

  puts "Generating pictures.. drawable-types"

  temp.resize_to_fill(36, 36).write(path + "drawable-ldpi-icon.png")
  temp.resize_to_fill(48, 48).write(path + "drawable-mdpi-icon.png")
  temp.resize_to_fill(72, 72).write(path + "drawable-hdpi-icon.png")
  temp.resize_to_fill(96, 96).write(path + "drawable-xhdpi-icon.png")
  temp.resize_to_fill(144, 144).write(path + "drawable-xxhdpi-icon.png")
  temp.resize_to_fill(192, 192).write(path + "drawable-xxxhdpi-icon.png")

  puts "Done!"
end