All Projects → Kagami → Avif.js

Kagami / Avif.js

Licence: other
AVIF polyfill for the browser

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Avif.js

Abortcontroller Polyfill
Polyfill for the AbortController DOM API and abortable fetch (stub that calls catch, doesn't actually abort request).
Stars: ✭ 273 (-31.58%)
Mutual labels:  polyfill
Polyfill Php70
This component provides features unavailable in releases prior to PHP 7.0.
Stars: ✭ 3,270 (+719.55%)
Mutual labels:  polyfill
Flif
Free Lossless Image Format
Stars: ✭ 3,668 (+819.3%)
Mutual labels:  image-compression
Bootstrap Ie8
Bootstrap 4 for IE8 and IE9
Stars: ✭ 278 (-30.33%)
Mutual labels:  polyfill
Ie8
some damn DOM fix for this damned browser
Stars: ✭ 297 (-25.56%)
Mutual labels:  polyfill
Css3 Mediaqueries Js
CSS3 Media Queries Shim
Stars: ✭ 333 (-16.54%)
Mutual labels:  polyfill
Imager
Automated image compression for efficiently distributing images on the web.
Stars: ✭ 266 (-33.33%)
Mutual labels:  image-compression
Wximagecompress
Image size quality compression, very close to WeChat picture compression strategy
Stars: ✭ 376 (-5.76%)
Mutual labels:  image-compression
Standardized Audio Context
A cross-browser wrapper for the Web Audio API which aims to closely follow the standard.
Stars: ✭ 300 (-24.81%)
Mutual labels:  polyfill
Imageflow
High-performance image manipulation for web servers. Includes imageflow_server, imageflow_tool, and libimageflow
Stars: ✭ 3,643 (+813.03%)
Mutual labels:  image-compression
Crunch
Crunch is a tool for lossy PNG image file optimization. It combines selective bit depth, color type, and color palette reduction with zopfli DEFLATE compression algorithm encoding using the pngquant and zopflipng PNG optimization tools. This approach leads to a significant file size gain relative to lossless approaches at the expense of a relatively modest decrease in image quality (see example images below).
Stars: ✭ 3,074 (+670.43%)
Mutual labels:  image-compression
Url Polyfill
Polyfill URL and URLSearchParams to match last ES7 specifications
Stars: ✭ 294 (-26.32%)
Mutual labels:  polyfill
Compress Images
Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif. NodeJs
Stars: ✭ 331 (-17.04%)
Mutual labels:  image-compression
Tinypng4mac
TinyPNG client for Mac
Stars: ✭ 3,025 (+658.15%)
Mutual labels:  image-compression
Fakeindexeddb
A pure JS in-memory implementation of the IndexedDB API
Stars: ✭ 373 (-6.52%)
Mutual labels:  polyfill
Compressorjs
JavaScript image compressor.
Stars: ✭ 3,500 (+777.19%)
Mutual labels:  image-compression
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+847.12%)
Mutual labels:  polyfill
Biscuit
一款Android 便捷高效图片压缩库,更多自定义,灵活配置,缩放部分逆向微信朋友圈压缩效果推算得来,效果非常接近!
Stars: ✭ 395 (-1%)
Mutual labels:  image-compression
Polyfill Ctype
This component provides a partial, native PHP implementation for the Ctype extension.
Stars: ✭ 3,774 (+845.86%)
Mutual labels:  polyfill
Loading Attribute Polyfill
Fast and lightweight dependency-free vanilla JavaScript polyfill for native lazy loading / the awesome loading='lazy'-attribute.
Stars: ✭ 335 (-16.04%)
Mutual labels:  polyfill


AVIF (AV1 Still Image File Format) polyfill for the browser
Start using superior image compression today!
🎊 🎉 DEMO 🎉 🎊

Features

  • Small, optional dependency, <4kb minified & gzipped
  • Intercepts AVIF fetch requests so works in any scenario
  • Uses native decoder if possible and should be reasonably fast

Supported browsers

With native decoder:

  • Chrome Desktop 70+
  • Firefox 63+ (with media.av1.enabled activated)
  • Firefox for Android 64+ (with media.av1.enabled and media.av1.use-dav1d activated)
  • Edge 18+ (with AV1 Video Extension installed)
  • Bromite 71+

With AV1 polyfill:

  • Chrome 57+
  • Firefox 53+
  • Edge 17+
  • Safari 11+

Usage

npm install avif.js
// Put this to reg.js and serve avif-sw.js from web root
// Both scripts should be transpilled (either manually with e.g. browserify or
// automatically by parcel)
require("avif.js").register("/avif-sw.js");
<body>
  <!-- Register worker -->
  <script src="reg.js"></script>

  <!-- Can embed AVIF with IMG tag now -->
  <img src="image.avif">

  <!-- Or via CSS property -->
  <div style="background: url(image2.avif)">
    some content
  </div>
</body>

That's it! Service worker will detect all fetch requests for AVIF files and decode them on the fly. It works with any complex scenarios of image embedding you might have, e.g. background-image in external CSS or XMLHttpRequest from a script.

See demo directory for the usage example.

To generate AVIF files you may use go-avif CLI utility.

Technical details for nerds

AVIF file is basically an AV1 keyframe packed inside ISOBMFF container, almost identical to the HEIF structure, except AV1 video format instead of HEVC is used. Latest versions of Chrome and Firefox support AV1 video decoding, but still can't display AVIF images, it usually takes some time before new format will be added. See e.g. Firefox issue.

Though abovementioned technical aspects of AVIF make it quite easy to implement as a tiny polyfill. All we need to do is repack AVIF as a single-frame AV1 video and decode it using native decoder. This is exactly what avif.js does. First it fetches the AVIF file into binary buffer, then parses the ISOBMFF structure, then searches and extracts the actual frame data (OBUs) and finally embeds it into MP4 video file. Now we can decode that video with standard <video> element and dump raw pixel data to temporary <canvas>.

Instead of forcing users to call some function every time they need to display AVIF file, fetch event interceptor powered by Service Worker API is used. It allows us to replace image data that browser doesn't know how to decode with some known one. avif.js uses BMP to avoid spending time on second compression of already decoded pixel data. It's very fast operation, we just need to write BMP header and copy color values in order. Finally we can deliver that created on the fly .bmp back to the browser and our image will appear on the page.

The actual process is a bit more complex, e.g. we can't create <video> element in a worker, so pass decoding request to the main thread and get result back. Also container fields of the video should correspond to properties of the still image, some offsets need to be fixed and so on. But you got the general idea.

Limitations of Service Worker API

  • Needs to be served from HTTPS
  • Doesn't work in Firefox/Edge Private Window
  • Requires page reload on first visit to display static assets

TODO

  • Benchmark
  • Check for AVIF support
  • Support for browsers without Service Workers

License

avif.js is licensed under CC0.
Demo images are taken from av1-avif repo.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].