Class: IconGenerator::TouchBuilder

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/icon_generator/touch_builder.rb

Instance Method Summary collapse

Methods included from Validator

#validate_arguments, #validate_file_status

Constructor Details

#initializeTouchBuilder

Initializes the default image sizes.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/icon_generator/touch_builder.rb', line 6

def initialize
    @sizes = [
        '152x152',
        '144x144',
        '120x120',
        '114x114',
        '76x76',
        '72x72',
        '57x57',
    ]
end

Instance Method Details

#build(source, destination) ⇒ Object

Builds apple-touch-icons from the given source file.

Parameters:

  • source (String)

    the source image file

  • destination (String)

    the output directory



22
23
24
25
26
27
28
29
30
# File 'lib/icon_generator/touch_builder.rb', line 22

def build(source, destination)
    @sizes.each do |size|
        new_image = "#{destination}/apple-touch-icon-#{size}-precomposed.png"
        build_size(source, size, new_image)
        if size == '57x57'
            build_size(source, '57x57', "#{destination}/apple-touch-icon-precomposed.png")
        end
    end
end

#build_single(source, destination) ⇒ Object

Builds a single 152x152 apple-touch-icon-precomposed from the given source file.

Parameters:

  • source (String)

    the source image file

  • destination (String)

    the output directory



37
38
39
# File 'lib/icon_generator/touch_builder.rb', line 37

def build_single(source, destination)
    build_size(source, '152x152', "#{destination}/apple-touch-icon-precomposed.png")
end

#build_size(source, size, new_image) ⇒ Object

Builds a given size of apple-touch-icon.

Parameters:

  • source (String)

    the source image file

  • size (String)

    the requested image size, in WxH format

  • new_image (String)

    the output image



46
47
48
49
50
# File 'lib/icon_generator/touch_builder.rb', line 46

def build_size(source, size, new_image)
    %x[convert '#{source}' -resize #{size}! #{new_image}]
    validate_file_status new_image
    puts Thor::Shell::Color.new.set_color("Built #{new_image}", :green)
end