feat: improve HEIC, HEIF and JPEG XL browser support detection#26122
feat: improve HEIC, HEIF and JPEG XL browser support detection#26122nicosemp wants to merge 1 commit intoimmich-app:mainfrom
Conversation
mertalev
left a comment
There was a problem hiding this comment.
Just a thought, but maybe we don't need it to process a full valid HEIF. We just need to know if the browser is willing to decode it, right? Maybe a truncated HEIF would give a different kind of error on an HEIF-compatible browser than one that can't decode it?
|
Just leaving this here as an fyi and a note for the future: the ImageDecoder.isTypeSupported does exactly what we want here. The one problem: safari doesn't support it. I don't know if/when they plan on implementing the api, but firefox only supports it since late 2024 so there's still hope. |
|
Long day, I just read the comments now. Thanks for the quick response as always. @meesfrensel that's a great suggestion, didn't know it existed. The current code already checks for @mertalev if this sounds good I'll rework my PR. Also Caniuse.com currently reports Safari 11-16.6 at 0.35% global usage, while version >=17.0 is at 0.77%. Nearly a third of Safari users don't have JPEG XL, HEIC or HEIF support. The alternative is to keep the base64 image check only for Safari, but maybe a version check in the userAgent is better. |
|
Using
It's worth noting this is only macOS - the vast majority of iOS devices support it. It's probably good to check it though. |
18b3f2a to
a559de7
Compare
|
|
|
Sorry I missed that. The currently proposed implementation won't error or anything since it checks for |
|
Good point about secure contexts, but I think this is fine for now. The status quo before was that these formats were only added for Safari, so this PR extends that to other browsers in secure contexts. |
|
Does Immich use telemetry to know what percentage of users access the website in/outside a secure context? I only access it locally, so definitely no https. Either way I'd rather add back the two base64 tests for non-secure contexts if that's ok with you. It would just use a |
|
Sure, I think that's okay. |
a559de7 to
a28e5f1
Compare
a28e5f1 to
3f600c7
Compare
3f600c7 to
8b47225
Compare
8b47225 to
0697027
Compare
0697027 to
ee62318
Compare
Description
Following up on #25599, this PR improves browser support detection for JXL, and HEIC/HEIF mime types by:
Details
The HEIC image was generated with ImageMagick from a 1x1 white PNG with this command:
and then turned into a base64 string:
base64 -w 0 output.heic > heic_b64.txtChanging the output to
.heifinstead of.heicyields the same result, so I guess any browser supporting one format would support the other one too? If this is certainly true I can remove the redundant HEIF test, otherwise it's best to keep it.Unfortunately the resulting string can't be as short as JPEG XL, but it's the shortest I could achieve.
If anyone else wants to improve it later, this slide suggests a theoretical minimum size of """only""" 386 bytes.
How Has This Been Tested?
Unfortunately this change would need tests running on different browsers to be validated:
supportedImageMimeTypesdefinition and test the added mime types on:image.jxl.enabledflag turned on in about:config -> it should add jxl.isSecureContexton secure and insecure contexts.ImageDecoder.isTypeSupportedon browsers with and without support for jxl, heic and heif mime types.Checklist:
src/services/uses repositories implementations for database calls, filesystem operations, etc.src/repositories/is pretty basic/simple and does not have any immich specific logic (that belongs insrc/services/)Please describe to which degree, if any, an LLM was used in creating this pull request.
No LLM.