0.0
Low commit activity in last 3 years
favicon_get is a Ruby library to find a website's favicon, ported from Python's favicon library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 5.0
~> 13.0
~> 1.50
~> 3.18

Runtime

 Project Readme

FaviconGet

FaviconGet is a Ruby gem for finding and retrieving website favicons (icons). It's a port of the popular favicon Python library.

Installation

Add this line to your application's Gemfile:

gem 'favicon_get'

And then execute:

$ bundle install

Or install it manually:

$ gem install favicon_get

Usage

Get all icons

require 'favicon_get'

icons = FaviconGet.get('https://www.ruby-lang.org/')
# => [Icon, Icon, Icon, ...]

# The first icon is usually the largest
icon = icons.first
puts "URL: #{icon.url}"
puts "Size: #{icon.width}x#{icon.height}"
puts "Format: #{icon.format}"

Download an icon

require 'favicon_get'
require 'open-uri'

icons = FaviconGet.get('https://www.ruby-lang.org/')
icon = icons.first

URI.open(icon.url) do |image|
  File.open("/tmp/ruby-favicon.#{icon.format}", "wb") do |file|
    file.write(image.read)
  end
end

# => /tmp/ruby-favicon.png

Additional parameters

require 'favicon_get'

# Custom headers
headers = {
  'User-Agent' => 'My custom User-Agent'
}

# Timeout and other parameters
FaviconGet.get('https://www.ruby-lang.org/',
                headers: headers,
                timeout: 5)

Icon object

Each icon is represented by the Icon struct with the following attributes:

  • url - Full URL to the icon file
  • width - Icon width in pixels (0 if unknown)
  • height - Icon height in pixels (0 if unknown)
  • format - File format/extension (e.g., 'ico', 'png')

Icons are sorted by size (larger first) and format priority.

Development

After checking out the repo, run make setup to install dependencies.

You can use the following Makefile commands for development:

  • make test - Run tests
  • make console - Get an interactive prompt with the gem loaded
  • make example - Run the example script
  • make build - Build the gem
  • make install - Install the gem locally
  • make up - Increment patch version (e.g., 0.1.0 → 0.1.1)
  • make up! - Increment minor version (e.g., 0.1.1 → 0.2.0)
  • make push - Push gem to RubyGems.org (requires permissions)

Requirements

License

This gem is available as open source under the terms of the MIT License.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/inem/favicon.