I have a 100% client-side web app that processes images picked by users. However I want users to be able to only pick formats that browser can read.
None of the below code really works without feature detection. Is there any standard or foolproof way to do it?
- This input let users pick ALL image formats including TIFF which only Safari can open:
<input type="file" accept="image/*" />
- This input let users pick certain file formats. However we have to maintain a list that may change in the future. Also AVIF is supported in most browsers EXCEPT Chromium Edge. So, a list as well as feature detection are needed.
<input type="file" accept=".apng, .gif, .jpg, .jpeg, .jfif, .pjpeg, .pjp, .png, .svg, .webp, .bmp, .ico, .cur" />
By "supporting", I would like the browser to be able to either:
Show it in an
<img />
tag.Draw it into a
<canvas>
.
Update: This question focuses mainly from the UI/UX perspective. I know there must be an error check anyway after user picks a file (users can pick any file they want, and even a corrupt PNG file for example). What I meant is, I would like to show the open dialog with just the formats that I know the browser would support so I don't show the error message after user already picks a file.