Recommended embedding method
This is the currently recommended embedding method, which uses JPEG-XT, AVIF and MP4 files generated by HDRJPG to attain a near-100% browser compatibility as per the current status of current standards and browser technology.
Embed the image in your HTML like this:
<div class="hdrjpg" data-mp4-src="image.mp4">
<picture>
<source srcset="image.avif" media="all and (min--moz-device-pixel-ratio:0) and (min-resolution: 3e1dpcm) {}" type="image/avif" />
<img src="image.jpg" style="image-rendering: -webkit-optimize-contrast;">
</picture>
</div>
Run this Javascript in your app:
if (
'MozAppearance' in document.documentElement.style /* Target Firefox */
||
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) /* Target Safari */
) {
document.querySelectorAll('.hdrjpg[data-mp4-src]').forEach((element) => {
element.querySelector('picture').remove();
let video = document.createElement('video');
video.src = element.dataset.mp4Src;
video.muted = true;
element.appendChild(video);
});
}
If you're using npm, you can just install the hdrjpg-js package instead.
Users with obsolete browser versions or without an HDR compatible screen will see a standard dynamic range instead.