Class: FaviconMaker::Creator

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

Constant Summary collapse

RECENT_IM_VERSION =
"6.8.0"
COLORSPACE_MIN_IM_VERSION =
"6.7.5"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_file_path, output_path, finished_block) ⇒ Creator

Returns a new instance of Creator.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/favicon_maker/creator.rb', line 16

def initialize(template_file_path, output_path, finished_block)
  @template_file_path = template_file_path
  @output_path        = output_path
  @finished_block     = finished_block

  im_version = fetch_image_magick_version

  if im_version
    print_image_magick_ancient_version_warning  if im_version < RECENT_IM_VERSION
    if im_version < COLORSPACE_MIN_IM_VERSION
      @colorspace_in   = "sRGB"
      @colorspace_out  = "RGB"
    else
      @colorspace_in   = "RGB"
      @colorspace_out  = "sRGB"
    end
  else
    print_image_magick_no_version_warning
    @colorspace_in   = "RGB"
    @colorspace_out  = "sRGB"
  end
end

Instance Attribute Details

#colorspace_inObject

Returns the value of attribute colorspace_in.



12
13
14
# File 'lib/favicon_maker/creator.rb', line 12

def colorspace_in
  @colorspace_in
end

#colorspace_outObject

Returns the value of attribute colorspace_out.



13
14
15
# File 'lib/favicon_maker/creator.rb', line 13

def colorspace_out
  @colorspace_out
end

#finished_blockObject

Returns the value of attribute finished_block.



14
15
16
# File 'lib/favicon_maker/creator.rb', line 14

def finished_block
  @finished_block
end

#output_pathObject

Returns the value of attribute output_path.



11
12
13
# File 'lib/favicon_maker/creator.rb', line 11

def output_path
  @output_path
end

#template_file_pathObject

Returns the value of attribute template_file_path.



10
11
12
# File 'lib/favicon_maker/creator.rb', line 10

def template_file_path
  @template_file_path
end

Instance Method Details

#icon(output_filename, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/favicon_maker/creator.rb', line 39

def icon(output_filename, options={})
  format  = options[:format]  || extract_format(output_filename)
  size    = options[:size]    || extract_size(output_filename)
  output_file_path = File.join(output_path, output_filename)

  validate_input(format, size)

  generate_file(template_file_path, output_file_path, size, format)

  finished_block.call(output_file_path, template_file_path) if finished_block
end