flagcdn

Crates.ioflagcdn
lib.rsflagcdn
version1.0.0
created_at2025-03-05 21:55:06.556172+00
updated_at2025-03-05 21:55:06.556172+00
descriptionA simple library for generating CDN links to country flag images in various sizes and formats.
homepage
repositoryhttps://github.com/INikonI/flagcdn-rs
max_upload_size
id1579885
size7,062
Nikon (INikonI)

documentation

README

flagcdn

It's a simple Rust library for generating CDN links to country flag images in various sizes and formats.

It uses https://flagcdn.com API (powered by https://flagpedia.net)

You can use it for embedding on your website/web-app or for programmatically download to keep flags in your projects up-to-date.

Usage example

use flagcdn::{flag_url, size::FixedHeight, Format};
use reqwest::blocking::Client;
use std::fs::File;

fn main() {
    let country_code = "JP";
    let format = Format::JPEG;

    let http = Client::new();
    let medium_japan_flag_url = flag_url(FixedHeight::XXL, country_code, format);
    let image_bytes = http
        .get(medium_japan_flag_url)
        .send()
        .expect("Failed to get image over http")
        .bytes()
        .expect("Failed to get response body as bytes");
    let mut file = File::create(format!("{country_code}.{format}")).expect("Failed to create file");
    file.write(&image_bytes)
        .expect("Failed to write image bytes to file");
    file.flush().expect("Failed to flush file");
}
Commit count: 4

cargo fmt