Kamel-Media / Kamel

Kotlin asynchronous media loading and caching library for Compose.
Apache License 2.0
595 stars 23 forks source link

Failed to Image::makeFromEncoded #42

Closed DatL4g closed 1 year ago

DatL4g commented 1 year ago

Loading some image URLs fail on Desktop JVM. (Not tested on Android)

Exception: Failed to Image::makeFromEncoded

Example URL: https://img-cdn.hltv.org/teamlogo/6LVaK1MVX06kO1ChAq22v6.svg?ixlib=java-2.1.0&s=1ad0be7366aab3ef6825996762c3e615

My KamelConfig:

KamelConfig {
    takeFrom(KamelConfig.Default)
    resourcesFetcher()
    svgDecoder()
    imageVectorDecoder()
}

Example Image display:

KamelImage(
    resource = asyncPainterResource("https://img-cdn.hltv.org/teamlogo/6LVaK1MVX06kO1ChAq22v6.svg?ixlib=java-2.1.0&s=1ad0be7366aab3ef6825996762c3e615"),
    contentDescription = null
)
luca992 commented 1 year ago

that's a svg. And the only way the library currently detects svgs is having a .svg extension. If you add .svg to the url: https://img-cdn.hltv.org/teamlogo/6LVaK1MVX06kO1ChAq22v6.svg?ixlib=java-2.1.0&s=1ad0be7366aab3ef6825996762c3e615.url it will work... kinda... I just tried and unfortunately there's an issue rendering it:

Screenshot 2023-06-24 at 9 29 45 PM
luca992 commented 1 year ago

svg's are not working on android yet fyi. So that definitely won't work

DatL4g commented 1 year ago

The URL already contains .svg as ending, so it should detect it. I guess it doesn't because of the query parameter.

luca992 commented 1 year ago

Yeah it would have to end in .svg not contain it atm.

luca992 commented 1 year ago

This is the issue.

when (data.toString().substringAfterLast(".")) {
    "svg" -> kamelConfig.loadSvgResource(data, resourceConfig)
    "xml" -> kamelConfig.loadImageVectorResource(data, resourceConfig)
    else -> kamelConfig.loadImageBitmapResource(data, resourceConfig)
}
DatL4g commented 1 year ago

Yeah I think it should parse this as a Uri or Url and just take the path and then check the ending. As fallback (when it can't be parsed) the existing method would be fine I guess

luca992 commented 1 year ago

released in v0.6.0 Thanks again!