Closed feinstein closed 3 months ago
Looking at the lib, I think this can be done by using the findDecoderForData
and then checking which decoder was selected.
Yeah I was going to suggest findDecoderForData. It will try decoding just the header for all the supported formats until it finds one that's most likely the format. It's always better to know what format you're decoding to avoid the library trying to guess.
Was this completed by a PR? I don't see it linked.
It was my understanding existing functionality provided what you needed.
Yes, but we could have an easier and simpler API to abstract this information
Normally I wouldn't go for a request like that, it could easily be done by the client app without needing to add even more clutter to the already cluttered API. But as I starting to type that argument, whatever I don't really care, it took 5 minutes to add. So here it is, https://github.com/brendan-duncan/image/commit/ab3eecb2ffdff09328a5be7f8b0e711521972cfe.
enum ImageFormat {
bmp, cur, exr, gif, ico, jpg, png, pnm, psd, pvr, tga, tiff, webp, custom, invalid
}
class Decoder {
ImageFormat get format => ImageFormat.invalid;
}
ImageFormat findFormatForData(List<int> data);
Decoder? createDecoderForFormat(ImageFormat format);
It will still be a while before any of this is published.
Looks awesome, thanks!
It would be useful if we could get a function that returns an image type. I think this is feasible for most image formats, since they have magic numbers. This function could return an enum with the possible image types, like
png
orjpg
.