• Stars
    star
    251
  • Rank 161,862 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Image processing library.

Image

Image processing library.

This library support encode/decode these formats:

Format Input Output
RawPixels RGBA 8 bits pixels
JPEG Baseline and progressive Baseline JPEG
PNG All supported color types Same as decoding
BMP โœ… Rgb8, Rgba8, Gray8, GrayA8
ICO โœ… โœ…
TIFF Baseline(no fax support) + LZW + PackBits Rgb8, Rgba8, Gray8
WebP No โœ…
AVIF No โœ…
PNM PBM, PGM, PPM, standard PAM โœ…
DDS DXT1, DXT3, DXT5 No
TGA โœ… Rgb8, Rgba8, Bgr8, Bgra8, Gray8, GrayA8
OpenEXR Rgb32F, Rgba32F (no dwa compression) Rgb32F, Rgba32F (no dwa compression)
farbfeld โœ… โœ…
SVG โœ…

See index.d.ts for API reference.

CI

Support matrix

node10 node12 node14 node16 node18
Windows x64 โœ“ โœ“ โœ“ โœ“ โœ“
Windows x32 โœ“ โœ“ โœ“ โœ“ โœ“
macOS x64 โœ“ โœ“ โœ“ โœ“ โœ“
macOS arm64 (m chips) โœ“ โœ“ โœ“ โœ“ โœ“
Linux x64 gnu โœ“ โœ“ โœ“ โœ“ โœ“
Linux x64 musl โœ“ โœ“ โœ“ โœ“ โœ“
Linux arm gnu โœ“ โœ“ โœ“ โœ“ โœ“
Linux arm64 gnu โœ“ โœ“ โœ“ โœ“ โœ“
Linux arm64 musl โœ“ โœ“ โœ“ โœ“ โœ“
Android arm64 โœ“ โœ“ โœ“ โœ“ โœ“
Android armv7 โœ“ โœ“ โœ“ โœ“ โœ“
FreeBSD x64 โœ“ โœ“ โœ“ โœ“ โœ“

Performance

System info

OS: macOS 12.3.1 21E258 arm64
Host: MacBookPro18,2
Kernel: 21.4.0
Shell: zsh 5.8
CPU: Apple M1 Max
GPU: Apple M1 Max
Memory: 9539MiB / 65536MiB
node bench/bench.mjs

@napi-rs/image 202 ops/s
sharp 169 ops/s
In webp suite, fastest is @napi-rs/image
@napi-rs/image 26 ops/s
sharp 24 ops/s
In avif suite, fastest is @napi-rs/image
UV_THREADPOOL_SIZE=10 node bench/bench.mjs

@napi-rs/image 431 ops/s
sharp 238 ops/s
In webp suite, fastest is @napi-rs/image
@napi-rs/image 36 ops/s
sharp 32 ops/s
In avif suite, fastest is @napi-rs/image

@napi-rs/image

See Full documentation for @napi-rs/image

Example

You can clone this repo and run the following command to taste the example below:

  • yarn install
  • node example.mjs
Optimization Raw Raw Size Optimized Size
losslessCompressPng()
Lossless
CC-BY-SA 3.0 by Niabot 888K 736K
pngQuantize({ maxQuality: 75 })
Lossy
CC-BY-SA 3.0 by Niabot 888K 248K
compressJpeg()
Lossless
192K 184K
compressJpeg(75)
Lossy
192K 104K
new Transformer(PNG).webpLossless()
Lossless
CC-BY-SA 3.0 by Niabot 888K 588K
new Transformer(PNG).webp(75)
Lossy
CC-BY-SA 3.0 by Niabot 888K 64K
Transformer(PNG).avif({ quality: 100 })
Lossless
CC-BY-SA 3.0 by Niabot 888K 536K
new Transformer(PNG).avif({ quality: 75, chromaSubsampling: ChromaSubsampling.Yuv420 })
Lossy
CC-BY-SA 3.0 by Niabot 888K 64K
import { readFileSync, writeFileSync } from 'fs'

import {
  losslessCompressPng,
  compressJpeg,
  pngQuantize,
  Transformer,
  ResizeFilterType,
  ChromaSubsampling,
} from '@napi-rs/image'
import chalk from 'chalk'

const PNG = readFileSync('./un-optimized.png')
const JPEG = readFileSync('./un-optimized.jpg')
// https://github.com/ianare/exif-samples/blob/master/jpg/orientation/portrait_5.jpg
const WITH_EXIF = readFileSync('./with-exif.jpg')
const SVG = readFileSync('./input-debian.svg')

writeFileSync('optimized-lossless.png', await losslessCompressPng(PNG))

console.info(chalk.green('Lossless compression png done'))

writeFileSync(
  'optimized-lossy.png',
  await pngQuantize(PNG, {
    maxQuality: 75,
  }),
)

console.info(chalk.green('Lossy compression png done'))

writeFileSync('optimized-lossless.jpg', await compressJpeg(readFileSync('./un-optimized.jpg')))

console.info(chalk.green('Lossless compression jpeg done'))

writeFileSync('optimized-lossy.jpg', await compressJpeg(readFileSync('./un-optimized.jpg'), { quality: 75 }))

console.info(chalk.green('Lossy compression jpeg done'))

writeFileSync('optimized-lossless.webp', await new Transformer(PNG).webpLossless())

console.info(chalk.green('Lossless encoding webp from PNG done'))

writeFileSync('optimized-lossy-png.webp', await new Transformer(PNG).webp(75))

console.info(chalk.green('Encoding webp from PNG done'))

writeFileSync('optimized-lossless-png.avif', await new Transformer(PNG).avif({ quality: 100 }))

console.info(chalk.green('Lossless encoding avif from PNG done'))

writeFileSync(
  'optimized-lossy-png.avif',
  await new Transformer(PNG).avif({ quality: 75, chromaSubsampling: ChromaSubsampling.Yuv420 }),
)

console.info(chalk.green('Lossy encoding avif from PNG done'))

writeFileSync(
  'output-exif.webp',
  await new Transformer(WITH_EXIF)
    .rotate()
    .resize(450 / 2, null, ResizeFilterType.Lanczos3)
    .webp(75),
)

console.info(chalk.green('Encoding webp from JPEG with EXIF done'))

writeFileSync('output-overlay-png.png', await new Transformer(PNG).overlay(PNG, 200, 200).png())

console.info(chalk.green('Overlay an image done'))

writeFileSync('output-debian.jpeg', await Transformer.fromSvg(SVG, 'rgba(238, 235, 230, .9)').jpeg())

console.info(chalk.green('Encoding jpeg from SVG done'))

More Repositories

1

canvas

High performance skia binding to Node.js. Zero system dependencies and pure npm packages without any postinstall scripts nor node-gyp.
Rust
1,635
star
2

ts-import-plugin

babel-import-plugin TypeScript Implement
TypeScript
567
star
3

learning-rxjs

Learning RxJS step by step
TypeScript
449
star
4

simple-git

Simple and fast git helper functions.
Rust
136
star
5

snappy

Fastest Snappy compression library in Node.js
Rust
119
star
6

uuid

Fastest RFC4122 UUIDs generator for Node.js
JavaScript
91
star
7

Clipboard

Manipulate Clipboard in Node.js via native API.
Rust
73
star
8

jsc-rs

JavaScript core Rust safe binding
Rust
67
star
9

redux-epics-decorator

Dumb decorators for redux & redux-observable & react-redux & redux-actions
TypeScript
59
star
10

blake-hash

Rust Blake hash bindings for Node.js.
Rust
36
star
11

sourcemap-decoder

https://github.com/getsentry/rust-sourcemap node bindings
Rust
33
star
12

woff-build

TTF to WOFF2
Rust
30
star
13

rust-to-nodejs-overhead-benchmark

Benchmark over Node.js binding frameworks in Rust
Rust
25
star
14

vercel-canvas

Sample Canvas App running on Vercel
HTML
23
star
15

ssh

https://github.com/warp-tech/russh Node.js binding
Rust
20
star
16

hns

Node.js http server framework powered by Hyper native binding.
TypeScript
19
star
17

sysinfo

System information
Rust
19
star
18

svg-to-pdf

Convert SVG to PDF
Rust
17
star
19

notify

https://github.com/notify-rs/notify Node.js binding via https://napi.rs
Rust
16
star
20

keyring-node

https://github.com/hwchen/keyring-rs Node.js binding via https://napi.rs. Including 100% compatible node-keytar alternative.
Rust
15
star
21

rxjs-webpack-treeshaking-example

Example for treeshaking
JavaScript
13
star
22

typescript-monorepo

Template project for typescript monorepo
JavaScript
12
star
23

lzma

https://docs.rs/lzma-rs binding to Node.js via https://napi.rs
Rust
10
star
24

wechat-api

JavaScript
9
star
25

ada-url

https://github.com/ada-url/ada Rust and Node.js binding
C++
9
star
26

Learning-Rx

ๅœจๅฎž่ทตไธญๅญฆไน  Rx
9
star
27

rxjs-in-react-demo

RxJS ๅœจ React ไธญ็š„ๅบ”็”จ็คบไพ‹้กน็›ฎ
TypeScript
8
star
28

html-parser

Parse html string to AST.
JavaScript
8
star
29

crypto-wasm

rust-crypto wasm build
JavaScript
8
star
30

dog

Watch dog for Node.js development
Rust
8
star
31

vuex-rx

RxJS Plugins for vuex
TypeScript
7
star
32

wx-fetch

ๅพฎไฟกๅฐๅบ”็”จ็š„ fetch polyfill
JavaScript
7
star
33

datafusion-node

Apache DataFusion Node.js binding
Rust
6
star
34

WechatBot

TypeScript
5
star
35

summer-page

JavaScript
5
star
36

node-ed25519

JavaScript
5
star
37

pnpm-duplicate-packages

Reproduction for duplicate packages bundled in pnpm project
JavaScript
5
star
38

node-threadsafe-function-loom

Play the Loom
Rust
4
star
39

Build-Promise

Build your own Promise
TypeScript
4
star
40

puppeteer-screencast-to-video

Puppeteer screencast frames to video
Rust
4
star
41

resume

Resume
TypeScript
4
star
42

Rust-OSS

Aliyun OSS utils
3
star
43

xcx-fucker

3
star
44

dart-rs

Dart rust binding library
Rust
3
star
45

blog

blog
TypeScript
3
star
46

css-minify-comparation

JavaScript
3
star
47

napi-rs-cli-testing

Testing package for @napi-rs/cli
JavaScript
2
star
48

zig-linker-issue

JavaScript
2
star
49

wechat-dingding-cryptor

Wechat/ Dingding cryptor
JavaScript
1
star
50

TypeScript-Webworker-Plugin

Generate webworker codes
1
star
51

next.js-remix-benchmark

TypeScript
1
star
52

ts-import-plugin-example

ts-import-plugin example project with create-react-app
JavaScript
1
star
53

node-crypto

rust-crypto bindings to nodejs
Rust
1
star
54

Cassanova

Teambition & Gitlab & Jenkins Webhook Bridge
TypeScript
1
star
55

Appelsin-Scroll

A cross browers custom scroll bar
JavaScript
1
star
56

frontend-mesh

Connect, control, and observe frontend services. Inspired by Istio.
1
star
57

Learning-FSharp

1
star
58

yarn-bug

1
star
59

node-ref-object-leak

JavaScript
1
star
60

angular_with_typescript

JavaScript
1
star
61

nestjs-vercel

1
star
62

traceurs

Fetch your data, eagerly.
TypeScript
1
star
63

vue-worker-rendering

Rendering HTML in service worker
JavaScript
1
star
64

nodejs-worker-thread-constructor-attribute-issue

C++
1
star
65

typescript-example-projects

JavaScript
1
star
66

nft-pnpm

@vercel/nft with pnpm
JavaScript
1
star
67

intelligent-link

Generate universal link or urlschema or App download url
1
star