Kamel-Media / Kamel

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

Decide type of image not using URL extension #81

Open kolesnikov-pasha opened 6 months ago

kolesnikov-pasha commented 6 months ago

Some links could not have any extension and provide, for example, svg images. In this case, image won't be shown correctly.

Example of link: https://img.recraft.ai/k0Ksvp7ONUcklX29-XZ42n0cxZC4DkiR1UnHLgBHv0I/rs:fit:768:768:0/raw:1/plain/abs://staging/images/85e93fd8-a732-4cb6-aaac-45e9285a4aaf

luca992 commented 6 months ago

yeah, right now it depends on extensions to determine type. If you have any suggestions on how to determine type from the file itself that would be helpful.

kolesnikov-pasha commented 6 months ago

The one thing I have in my mind is to 1) check all caches for the key. If it is present then decide type based on cache type 2) if no cached image for this key, download file and decide its type based on the content, I guess it shouldn't be hard (for example, svg files always start with <svg and so on)

I'll try to research this question and make PR later this week

kolesnikov-pasha commented 6 months ago

Maybe it is possible to use this tool or to port its part on Kotlin: https://imagemagick.org/script/identify.php

eskatos commented 5 months ago

HTTP Content-Type header could be a good source of information for this

luca992 commented 5 months ago

HTTP Content-Type header could be a good source of information for this

Yeah that could help for network requests 👍