Add `Image::uri()` (#4720)

`uri()` for image

The advantages of this are :

1. No need for `ctx()` and `source()`
2. Displays `name.gif#0` as `name.gif`
This commit is contained in:
rustbasic 2024-07-05 15:20:20 +09:00 committed by GitHub
parent 9a4c46289e
commit ad597a8491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 0 deletions

View File

@ -283,6 +283,20 @@ impl<'a> Image<'a> {
}
}
/// Returns the URI of the image.
///
/// For GIFs, returns the URI without the frame number.
#[inline]
pub fn uri(&self) -> Option<&str> {
let uri = self.source.uri()?;
if let Ok((gif_uri, _index)) = decode_gif_uri(uri) {
Some(gif_uri)
} else {
Some(uri)
}
}
#[inline]
pub fn image_options(&self) -> &ImageOptions {
&self.image_options