rsgt 0.3.0

Rust simple GUI Toolkit
//========================================================================
// RSGT | graphic.rs - https://overtimecoder.github.io
//------------------------------------------------------------------------
// Image manipulation
//------------------------------------------------------------------------
//
// Author LatteS
//
// File was created in 2022/12/31
//
//========================================================================

//! # Graphics processing
use crate::error::Error;
use std::path::Path;
use std::process::exit;
use winit::window::Icon;

/// Load icon from path
pub fn load_icon(path: &Path) -> Icon {
    let (icon_rgba, icon_width, icon_height) = {
        let image = match image::open(path) {
            Ok(img) => img.into_rgba8(),
            Err(err) => {
                let message = format!("{}\nExit the application", err.to_string());
                Error::new(message.as_str()).error();
                exit(1);
            }
        };
        let (width, height) = image.dimensions();
        let rgba = image.into_raw();
        (rgba, width, height)
    };
    Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon")
}