| Crates.io | image_info |
| lib.rs | image_info |
| version | 0.2.0 |
| created_at | 2025-04-08 18:49:32.515617+00 |
| updated_at | 2025-04-08 19:42:33.369322+00 |
| description | A library to get base image information from a file |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1625813 |
| size | 7,541,065 |
A library to extract base information of the image file:
To get MIME type uses infer crate. If the file does not have a valid image MIME type, the tree_magic_mini crate is used
by fallback to get the real MIME type as infer returns an error if the MIME is not for image (e.g. "plain/text").
To get dimensions uses imagesize crate.
Reports error codes and error messages on failure.
Can render result as JSON string (useful for using from other languages as wrapper with binary code calling
if the FFI is not an option). If you don't need this feature you can disable it within your Cargo.toml:
[dependencies]
image_info = {version = "0.2.0", default-features = false}
fn main() {
let args: Vec<String> = std::env::args().collect();
let path: &str = match args.get(1) {
Some(arg) => arg,
None => {
println!("No path argument specified");
std::process::exit(image_info::CODE_BAD_ARGS);
}
};
let info = image_info::process_path(path);
println!("{:?}", info);
//InfoResult { mime_type: Some("image/jpeg"), width: Some(1920), height: Some(1280), error_message: None, error_code: 0 }
//InfoResult { mime_type: Some("text/html"), width: None, height: None, error_message: Some("Error: mime type is not image/*: text/html"), error_code: 2 }
//if "render" feature is enabled
println!("{}", info.render());
//{"mime_type":"image/jpeg","width":7724,"height":5148,"error_message":null,"error_code":0}
//{"mime_type":"text/html","width":null,"height":null,"error_message":"Error: mime type is not image/*: text/html","error_code":2}
std::process::exit(info.get_error_code());
}