Module: JekyllFaviconGenerator::Ico

Extended by:
Ico
Included in:
Ico
Defined in:
lib/jekyll-favicon-generator/ico.rb

Defined Under Namespace

Classes: BitMapInfoHeader, IconDir, IconDirEntry

Instance Method Summary collapse

Instance Method Details

#img_to_ico(src, ico, sizes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll-favicon-generator/ico.rb', line 17

def img_to_ico(src, ico, sizes)
  File.open(ico, "wb") do |f|
    f.write icon_dir sizes

    sizes.each do |width|
      height = width
      f.write bitmap_info_header width, height

      img = ::Vips::Image.thumbnail src, width, :height => height
      img = img.flip(:vertical) # Flip the image since bitmap is stored bottom to top
      img = img.colourspace :srgb # Ensure srgb colourspace
      f.write bitmap_xor_mask img, width, height
      f.write bitmap_and_mask img, width, height
    end
  end
  true
end