Milimg is a internal image format used by Milthm which acts as a simple AV1 container. This is a reference milimg encoder and decoder based on WebCodecs API.
Note: This library only supports browser environment, requires WebCodecs API support For unknown reason, some jpeg image may not be encoded successfully
npm install milimg
# or
yarn add milimgOr use CDN
<script type="module">
import {
decodeMilimg,
encodeMilimg
} from 'https://cdn.jsdelivr.net/npm/milimg/lib/index.js';
</script>import { encodeMilimg } from 'milimg';
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
const imageBuffer = Buffer.from(arrayBuffer);
const milimgBuffer = await encodeMilimg(imageBuffer, 0);import { decodeMilimg } from 'milimg';
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
const milimgBuffer = Buffer.from(arrayBuffer);
const pngBuffer = await decodeMilimg(milimgBuffer);Encode image to milimg format
Parameters:
imageBuffer- Image file buffer (support PNG/JPEG/WebP format)quality- Encoding quality(qp) (0-63), the lower the quality, the higher the quality, default is 0
Returns:
Promise<Buffer>- milimg buffer
Example:
const milimgBuffer = await encodeMilimg(imageBuffer, 28);Decode milimg format to PNG
Parameters:
buffer- milimg buffer
Returns:
Promise<Buffer>- PNG buffer
Example:
const pngBuffer = await decodeMilimg(milimgBuffer);Parse milimg container header
Parameters:
buffer- milimg buffer
Returns:
MilimgHeader- Object containing version, size, and payload information
Example:
const header = parseMilimgContainer(milimgBuffer);
console.log(header.width, header.height, header.version);- Version 0: Image without alpha channel
- Version 1: Image with alpha channel (RGBA)
The library is originally created by Q78KG based on qaqFei's reverse engineering results, later the disclosure of technical details and specs of milimg format is authorized and it became a official project.
milimg.js - reference encoder & decoder implementation of the milimg format
Copyright (C) 2024-present Morizero, Hoshino Yumetsuki
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.