Skip to content

inem/favicon

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Find a website's favicon.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 79.6%
  • Makefile 19.8%
  • Shell 0.6%