Checking the output type of a browser image conversion matters because a successful-looking export can still be the wrong format. A browser's ability to decode and display a file, including AVIF or TIFF, says nothing about its ability to encode that same format. The only reliable check is to inspect the actual output: its MIME type, its first bytes, and its appearance, rather than trusting the filename a tool hands you.
Why can't you trust a file's extension?
Changing or assigning a file extension does not change the bytes inside the file. A browser-based converter can label an export photo.avif while the underlying data is still a PNG, because many tools build the output filename from the format you requested rather than from what the encoder actually produced. If the encoder quietly substituted a different format, the extension becomes misleading rather than descriptive.
How do you identify a file type using magic bytes?
Every common image format starts with a fixed sequence of bytes before any pixel data: PNG begins with a specific eight-byte signature, JPEG starts with the bytes FF D8, and so on. Reading these bytes confirms what a file actually is, independent of its name. A script can read a File or Blob's contents as an array buffer and compare the first several bytes against known signatures.
What happens when canvas.toBlob() can't encode what you asked for?
Many in-browser converters rely on the Canvas API: draw the image, then call toBlob() with a requested MIME type. MDN documents that when the browser does not support encoding to that type, toBlob() defaults to image/png instead of raising an error. Asking for image/avif can return a valid PNG blob with no exception and no console warning, and the filename a script builds beforehand may still say .avif even though the content changed.
How to check browser image conversion output type
Verifying the output does not require special tools, just a short sequence of checks before you trust a result or run a larger batch.
- →Capture the resulting Blob object itself, not just the filename the tool suggests.
- →Read blob.type and compare it with the MIME type you actually requested.
- →If the two differ, treat the file as the fallback format, since the encoder did not do what was asked.
- →Read the first bytes of the file to confirm the signature matches the type you expect.
- →Open the file in an independent viewer or editor and confirm dimensions and appearance match the source.
Illustrative example, not a measured test of any specific browser: a script requests image/avif from canvas.toBlob() for a 1200 by 800 photograph. The call completes without an error. Checking blob.type returns image/png, which confirms the browser fell back silently rather than producing AVIF. Renaming the file to photo.avif would not change what it contains; opening it with a hex viewer would still show a PNG signature. Encoder support varies and changes over time, so this should be checked in the environment you actually use rather than assumed.
Why does browser decoding support differ from encoding support?
Being able to display a format is not the same as being able to produce it. MDN's image format guide notes that browser support varies by format and that newer formats such as AVIF and WebP need handling beyond basic display capability. The practical result: most current browsers can decode AVIF well enough to show it on screen, but canvas.toBlob() generally cannot encode AVIF, which is exactly the gap that produces a PNG fallback instead of the requested output.
| Format | Typical browser decode | Typical canvas.toBlob() encode |
|---|---|---|
| JPEG | Widely supported | Widely supported |
| PNG | Widely supported | Widely supported |
| WebP | Supported in current browsers | Varies by browser |
| AVIF | Supported in current browsers for display | Generally not supported via canvas.toBlob() |
| TIFF | Not guaranteed across browsers | Not guaranteed across browsers |
How do you validate a batch conversion before scaling up?
Run one representative file through the whole pipeline before processing a folder of hundreds. Check blob.type against the requested MIME type, check the magic bytes, and open the result in a viewer independent of the tool that made it. Keep the original file untouched so you can compare it directly against the output.
Some limits are not about encoding format at all. Converting an SVG to a raster image fixes its pixel dimensions instead of preserving vector scaling, and a format that only supports a single frame will take just the first frame of a multi-frame source rather than exporting animation. Neither of these shows up as an error; both only show up when you actually open and compare the result. If you are using a browser-based tool that processes files locally on your own device, the same encoder limits still apply: local processing changes where the work happens, not what formats the browser's own encoder can produce, and very large files or large batches remain limited by your device's available memory and processing power.
Before converting a full folder, convert one file first, compare blob.type against what you requested, and open the result in a separate viewer. That single check, repeated for each new format or browser you rely on, catches a silent fallback before it spreads through an entire batch of mislabeled files.