Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@volue/wasm-codecs-mozjpeg

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@volue/wasm-codecs-mozjpeg

MozJPEG image encoder in WebAssembly

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
2
Created
Source

@wasm-codecs/mozjpeg npm version license downloads

MozJPEG WebAssembly Codec

Table of contents

Installation

npm install @wasm-codecs/mozjpeg

Requirements:

  • Node.js 10 or later

Usage

import encode from '@wasm-codecs/mozjpeg';

(async () => {
  const encodedImage = await encode(image, inputInfo, encodeOptions);
})();

API

encode(image, inputInfo, encodeOptions?): Buffer

Returns a buffer containing the compressed image data.

image: Buffer

A raw RGB image input buffer.

inputInfo: InputInfo

Those are required informations about the raw input image. Channels specifies the amount of channels in the image: Buffer param and defaults to 3 (RGB).

type InputInfo = {
  width: number;
  height: number;
  channels?: number;
}
encodeOptions?: EncodeOptions

All encoding options are optional and fall back to the default values.

type EncodeOptions = {
  quality?: number;
  baseline?: boolean;
  arithmetic?: boolean;
  progressive?: boolean;
  optimizeCoding?: boolean;
  smoothing?: number;
  colorSpace?: ColorSpace;
  quantTable?: number;
  trellisMultipass?: boolean;
  trellisOptZero?: boolean;
  trellisOptTable?: boolean;
  trellisLoops?: number;
  autoSubsample?: boolean;
  chromaSubsample?: number;
  separateChromaQuality?: boolean;
  chromaQuality?: number;
}

Examples

Using sharp in Node.js

import fs from 'fs';
import sharp from 'sharp';
import encode from '@wasm-codecs/mozjpeg';

(async () => {
  // read input image and convert it to a raw buffer using sharp
  const {
    data,
    info: { width, height, channels },
  } = await sharp('in.jpg')
    .raw()
    .toBuffer({ resolveWithObject: true });

  // encode the image using @wasm-codecs/mozjpeg
  const output = await encode(data, { width, height, channels });

  // save the image to the file system
  fs.writeFileSync('out.jpg', output);
})();

License

Licensed under the MIT license.

© Copyright Cyril Wanner

Keywords

wasm

FAQs

Package last updated on 22 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts