feat: display file size

This commit is contained in:
electria 2026-07-31 17:23:29 -07:00
commit 6fa0e29eae
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
3 changed files with 16 additions and 1 deletions

View file

@ -2,6 +2,7 @@ use std::{
borrow::Cow,
env,
ffi::OsStr,
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
};
@ -11,6 +12,7 @@ use iced::{
theme, widget, window,
};
use image::{EncodableLayout, RgbaImage, imageops};
use size::Size;
mod kra;
mod utils;
@ -179,10 +181,15 @@ impl State {
fn load_image(&mut self, path: impl AsRef<Path>) -> Result<Task<Message>, String> {
utils::load_image(&path).map(|image| {
self.info = Some(format!(
"{} {}x{}",
"{} {} {}x{}",
path.as_ref()
.file_name()
.map_or(Cow::Borrowed("[no file]"), OsStr::to_string_lossy),
path.as_ref()
.metadata()
.map_or(Cow::Borrowed("[no size]"), |m| Cow::Owned(
Size::from_bytes(m.size()).to_string()
)),
image.width(),
image.height(),
));