.png, .jpeg, .webp, etc. -> .avif
AVIF Image Encoder for JavaScript (only support for browsers, no supports for Node.js/Deno/Bun etc.)
ブラウザ JavaScript で AVIF 画像をエンコーディングするためのスクリプト
# install all sources into "avif-encoder.js" directory in your current path
git clone "https://github.com/m4k15y6666fk/avif-encoder.js.git"
// import the module
import Avif from "./avif-encoder.js/dist/index.js";
// initialize the encoder
const avif = new Avif();
await avif.init();
// ...
// ...
// encode image file (File Object) into Uint8Array
// Uint8Array - https://developer.mozilla.org/en-US/docs/Web/API/Uint8Array
const array = await avif.encode(
file, // File Object - https://developer.mozilla.org/en-US/docs/Web/API/File
{
quality: 60,
speed: 4,
debug: false
}
);
// OR
// encode ImageData into Uint8Array
const array = await avif.encode_from_pixels(
pixels, // ImageData Object - https://developer.mozilla.org/en-US/docs/Web/API/ImageData
{
quality: 60,
speed: 4,
debug: false
}
)
Note
Depending on the environment, encoding may take about 200 seconds or more.
環境によっては、エンコードには 200 秒以上の時間がかかる可能性があります.
rav1e-based pure Rust library for encoding images in AVIF format (powers the cavif tool)