Fetch favicons from webpages and convert them into various image formats!
You can install FaviconParty through RubyGems
$ gem install favicon_party
Or add it to your application's Gemfile and install via bundler
gem 'favicon_party'
FaviconParty parses the html response of the query url to find favicon links and falls back to checking /favicon.ico
image = FaviconParty.fetch! "github.com"
# => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
If a valid favicon isn't found:
FaviconParty.fetch! "http://example.com" # raises FaviconNotFound
FaviconParty.fetch "http://example.com" # nil
To access the source favicon data and convert it into various image formats:
image.source_data # binary favicon image data
image.to_png # binary 16x16 png data
image.base64_png # base64-encoded 16x16 png data
You can load favicon data from image files:
image = FaviconParty.load "/path/to/favicon.ico"
# => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
image.valid? # true
And also load them directly from their source URLs:
image = FaviconParty.load "https://github.com/favicon.ico"
# => #<FaviconParty::Image mime_type: "image/x-icon", size: 6518>
FaviconParty also provides a command-line script for fetching favicons. By
default, it attempts to fetch a favicon from the given URL and prints it to stdout.
Run fetch_favicon --help
to see the list of options.
fetch_favicon github.com # prints favicon data to STDOUT
fetch_favicon --format png github.com # prints 16x16 favicon png to STDOUT
fetch_favicon example.com # prints an error to STDERR
- Ruby 2.0.0+
- Nokogiri - parsing html
- Imagemagick - validating and converting favicons
- Curl - http client
- File - mime-type detection