From 53ec7333c318924914d318c8f00ebe64dd7d63aa Mon Sep 17 00:00:00 2001 From: Kelvin Leung Date: Wed, 17 Dec 2025 15:08:51 +0000 Subject: [PATCH] Fix media type with optional parameters (#7739) I am having an issue loading this image "https://stacks.stanford.edu/image/iiif/wy534zh7137/SULAIR_rosette/full/400,/0/default.jpg". It has a mime type of "image/jpeg; charset=utf-8", which is not common. The code doesn't parse the full string that includes the optional parameter "charset=utf-8" to create the jpeg image format. A line is added to take only the mime type in the media type before the ";" and ignore the optional parameters. * Closes * [x] I have followed the instructions in the PR template Co-authored-by: leungkkf --- crates/egui_extras/src/loaders/image_loader.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/egui_extras/src/loaders/image_loader.rs b/crates/egui_extras/src/loaders/image_loader.rs index 6d735f688..d6d056418 100644 --- a/crates/egui_extras/src/loaders/image_loader.rs +++ b/crates/egui_extras/src/loaders/image_loader.rs @@ -50,8 +50,11 @@ fn is_supported_mime(mime: &str) -> bool { } } + // Some servers may return a media type with an optional parameter, e.g. "image/jpeg; charset=utf-8". + let (mime_type, _) = mime.split_once(';').unwrap_or((mime, "")); + // Uses only the enabled image crate features - ImageFormat::from_mime_type(mime).is_some_and(|format| format.reading_enabled()) + ImageFormat::from_mime_type(mime_type).is_some_and(|format| format.reading_enabled()) } impl ImageLoader for ImageCrateLoader {