View Source Faviconic (faviconic v0.2.1)

Fetch a favicon from a URL, with multiple fallbacks.

Full online documentation is available here.

You can find the package on Hex here.

For example.com it will first try example.com/favicon.ico, then it will try to find the icon file path in the HTML, and if it does, try to fetch that icon. If both fail, then it will query https://www.google.com/s2/favicons?domain=example.com

To use

case Faviconic.fetch("google.com") do
  {:ok, image} -> image # image itself is returned
  {:error, error_message} -> IO.inspect(error_message)
end
case Faviconic.get("google.com") do
  {:ok, url} -> url # icon URL is returned
  {:error, error_message} -> IO.inspect(error_message)
end

MIT License

Copyright 2022 Bonfire Networks Copyright 2018 Zak Miller (author of the library Faviconic was forked from: https://github.com/ZakMiller/fetch-favicon)

Summary

Functions

Fetch the binary contents of a favicon file for a domain

Find a favicon URL (or fetch its binary contents by setting the fetch_image? param to true) given HTML page contents. Use this if you already fetched the HTML page to avoid doing it twice.

Get the URL of a favicon file for a domain (or fetch its binary contents by setting the fetch_image? param to true)

Parses an HTML page and tries to find a favicon URL in it

Functions

Fetch the binary contents of a favicon file for a domain

Link to this function

find(url, html_body, fetch_image? \\ false)

View Source

Find a favicon URL (or fetch its binary contents by setting the fetch_image? param to true) given HTML page contents. Use this if you already fetched the HTML page to avoid doing it twice.

Parses the HTML and tries to find a favicon in it (if provided), and otherwise tries other techniques.

Link to this function

get(url, fetch_image? \\ false)

View Source

Get the URL of a favicon file for a domain (or fetch its binary contents by setting the fetch_image? param to true)

Tries to obtain a favicon for the site. It first tries the url/favicon.ico (for speed). Then it uses the some third-party favicon services to try retrieving a favicon. Lastly it tries to find a path to an icon URL in the HTML page.

If you do not pass http:// or https://, http:// is assumed.

Link to this function

parse(url, html_body, fetch_image? \\ false)

View Source

Parses an HTML page and tries to find a favicon URL in it