Sha256: 4284c1238196b7b7933f5dc374e3aec3ddaa85651fedbf2e919e2facaf8ee603

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module IconGenerator
    class TouchBuilder
        include IconGenerator::Validator

        # Initializes the default image sizes.
        def initialize
            @sizes = [
                '152x152',
                '144x144',
                '120x120',
                '114x114',
                '72x72',
                '57x57',
            ]
        end

        # Builds apple-touch-icons from the given source file.
        #
        # @param source [String] the source image file
        # @param destination [String] the output directory
        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

        # Builds a single 152x152 apple-touch-icon-precomposed from the
        # given source file.
        #
        # @param source [String] the source image file
        # @param destination [String] the output directory
        def build_single(source, destination)
            build_size(source, '152x152', "#{destination}/apple-touch-icon-precomposed.png")
        end

        # Builds a given size of apple-touch-icon.
        #
        # @param source [String] the source image file
        # @param size [String] the requested image size, in WxH format
        # @param new_image [String] the output image
        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
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
icon_generator-0.10.0 lib/icon_generator/touch_builder.rb