#favicon #icons #command-line-tool

bin+lib favilib

Library for fetching and parsing favicons from websites

6 releases (breaking)

0.5.1 Apr 16, 2024
0.5.0 Apr 15, 2024
0.4.0 Apr 14, 2024
0.3.0 Apr 12, 2024
0.1.0 Apr 8, 2024

#1729 in Parser implementations

Download history 1/week @ 2024-05-28 13/week @ 2024-06-04 7/week @ 2024-06-11 17/week @ 2024-06-18 2/week @ 2024-06-25 6/week @ 2024-07-02 40/week @ 2024-07-23 25/week @ 2024-07-30

268 downloads per month

MIT license

25KB
492 lines

crates.io version docs.rs

favilib

Favicon Fetcher written in Rust. Contains library as well as CLI tool.

[!WARNING] This is a work in progress. The library is not yet stable.

Library

use favilib::{fetch, Favicon, ImageSize, ImageFormat, Url, Client};

let url = Url::parse("https://github.com").unwrap();

// Fetch and export image directly
let _ = fetch(&url, ImageSize::Large, ImageFormat::Png, "favicon.png", None);

// Fetch image and get it as a struct
let client = Client::new(); 
let favicon = Favicon::fetch(&url, Some(client)).unwrap();

let resized_favicon = favicon.resize(ImageSize::Custom(32,32)).unwrap();
let reformatted_favicon = resized_favicon.change_format(ImageFormat::Png).unwrap();
reformatted_favicon.export("favicon.png").unwrap();

CLI

Installation

CLI can be installed via cargo by running cargo install favilib

Interface

# Format will be changed based on the file ending
favilib fetch github.com --size large --path favicon.png 

# Format can also be specified explicitly and bytes can be printed to stdout if path is omitted. And size can be specified explicitly
favilib fetch github.com --size 32,32 --format ico

# Prints the extracted URL of the favicon to stdout
favilib fetch github.com --url-only --stdout

Dependencies

~10–21MB
~322K SLoC