Image operation rust library

Overview

@napi-rs/image

Image processing library.

CI install size Downloads

Support matrix

node10 node12 node14 node16 node17
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

Lossless compression

PNG

export interface PNGLosslessOptions {
  /**
   * Attempt to fix errors when decoding the input file rather than returning an Err.
   * Default: `false`
   */
  fixErrors?: boolean | undefined | null
  /**
   * Write to output even if there was no improvement in compression.
   * Default: `false`
   */
  force?: boolean | undefined | null
  /** Which filters to try on the file (0-5) */
  filter?: Array<number> | undefined | null
  /**
   * Whether to attempt bit depth reduction
   * Default: `true`
   */
  bitDepthReduction?: boolean | undefined | null
  /**
   * Whether to attempt color type reduction
   * Default: `true`
   */
  colorTypeReduction?: boolean | undefined | null
  /**
   * Whether to attempt palette reduction
   * Default: `true`
   */
  paletteReduction?: boolean | undefined | null
  /**
   * Whether to attempt grayscale reduction
   * Default: `true`
   */
  grayscaleReduction?: boolean | undefined | null
  /**
   * Whether to perform IDAT recoding
   * If any type of reduction is performed, IDAT recoding will be performed regardless of this setting
   * Default: `true`
   */
  idatRecoding?: boolean | undefined | null
  /** Whether to remove ***All non-critical headers*** on PNG */
  strip?: boolean | undefined | null
  /** Whether to use heuristics to pick the best filter and compression */
  useHeuristics?: boolean | undefined | null
}
export function losslessCompressPng(input: Buffer, options?: PNGLosslessOptions | undefined | null): Buffer

JPEG

export interface JpegCompressOptions {
  /** Output quality, default is 100 (lossless) */
  quality?: number | undefined | null
  /**
   * If true, it will use MozJPEG’s scan optimization. Makes progressive image files smaller.
   * Default is `true`
   */
  optimizeScans?: boolean | undefined | null
}
export function compressJpeg(input: Buffer, options?: JpegCompressOptions | undefined | null): Buffer
Comments
  • Add support for getting raw pixels

    Add support for getting raw pixels

    As the inverse of #8, it would be nice to get the raw pixels of an image for the purpose of detecting a color pallet.

    For example, perhaps a new method, getImageData(), which is how it would be solved with <canvas>:

    import { readFileSync } from 'fs'
    import palette = from 'get-rgba-palette'
    import { Image } from '@napi-rs/image'
    
    const decoder = new Transformer(readFileSync('./img.jpg'))
    const pixels = decoder.getImageData()
    const colors = palette(pixels, 5)
    

    https://github.com/mattdesl/get-rgba-palette

    opened by styfle 2
  • Error: `BUFFER_TOO_SMALL` when using `pngQuantize` to compress small file

    Error: `BUFFER_TOO_SMALL` when using `pngQuantize` to compress small file

    I'm using @napi-rs/image in my project to compress images, and I ran into a bug when trying to compress PNG images with pngquant. When I try to compress very small PNG images, the program crashes. I also tried using imagemin-pngquant and didn't encounter this issue, so I suspect it might be related to the implementation of @napi-rs/image.

    You can reproduce this problem by following these steps:

    $ git clone https://github.com/Asuka109/napi-rs-image-sample.git
    $ cd napi-rs-image-sample
    $ pnpm i
    $ node transform.mjs
    node:internal/process/esm_loader:97
        internalBinding('errors').triggerUncaughtException(
                                  ^
    
    [Error: Create image failed BUFFER_TOO_SMALL] { code: 'GenericFailure' }
    

    Is this a known issue, or is there something I can do to fix it?

    Thank you for your time.

    opened by Asuka109 0
  • feat: async Encoder class

    feat: async Encoder class

    • [x] Replace AVIF encoder with https://github.com/njaard/libavif-rs
    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
    
    opened by Brooooooklyn 0
  • Add support for setting raw pixels

    Add support for setting raw pixels

    There are a lot of requests for blurhash support in Next.js, and I'm wondering if we could add a method to Image to set raw pixels.

    https://github.com/woltapp/blurhash/issues/56#issuecomment-877538877

    Perhaps something like setPixels():

    import { decode } from 'blurhash'
    import Image from '@napi-rs/image'
    
    const pixels = decode('LEHV6nWB2yk8pyo0adR*.7kCMdnj', 32, 32) // Uint8ClampedArray
    const image = new Image(32, 32)
    image.setPixels(pixels)
    const src = image.src  // data:image/png;base64,iVBORw0KGgoAA...
    
    opened by styfle 0
  • oxipng seems to be missing the strip `safe` and `Vec<String>` option

    oxipng seems to be missing the strip `safe` and `Vec` option

    • Docs: https://docs.rs/oxipng/5.0.1/oxipng/enum.Headers.html

    • Test: https://github.com/shssoichiro/oxipng/blob/7ffbe1fb7865a8e97512e63cef06bebc245059a1/tests/flags.rs#L224-L230

    • safe would remove all auxiliary data blocks that do not potentially affect the rendering of the image. For example, Text Chunks will be removed.

    • all would maintain the current behavior and remove all auxiliary data blocks.

    https://github.com/Brooooooklyn/Image/blob/e61083611a6e16e07b38eaefee8d2537c93efe2c/packages/binding/src/png.rs#L131-L139

    imageoptim uses safe by default.

    https://github.com/ImageOptim/ImageOptim/blob/d8d6bc528f0b19253585d824851e320db3261d03/imageoptim/Backend/Workers/OxiPngWorker.m#L31-L33

    opened by yisibl 0
Releases(@napi-rs/[email protected])
Owner
LongYinan
TypeScript at day, Rustacean at night. Coding for fun.
LongYinan
Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes

What is Lust? Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes with scaling in mind.

Harrison Burt 242 Dec 22, 2022
Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Jacob 258 Dec 30, 2022
Rust library for fast image resizing with using of SIMD instructions.

fast_image_resize Rust library for fast image resizing with using of SIMD instructions. CHANGELOG Supported pixel formats and available optimisations:

Kirill Kuzminykh 115 Jan 5, 2023
An advanced image processing library for Rust.

ImageProc Maintainers: @chyh1990 Note: this project is under active depvelopment, API may change! imageproc is a advanced image proccessing library fo

Chen Yuheng 97 Oct 18, 2022
Rust library to get image size and format without loading/decoding

imageinfo-rs Rust library to get image size and format without loading/decoding. The imageinfo don't get image format by file ext name, but infer by f

xiaozhuai, Weihang Ding 47 Dec 30, 2022
ePaperify: Framebuffer/image pre-processing library for e-Paper displays

ePaperify: Framebuffer/image pre-processing library for e-Paper displays

Jackson Ming Hu 5 Mar 15, 2022
tai (Terminal Ascii Image) tool to convert images to ascii written in Rust

TAI Terminal Ascii Image A tool to convert images to ascii art written in Rust ?? Notes This tool is still in development stage. Contributions All Con

Mustafa Salih 258 Dec 5, 2022
A simple image average color extractor written in 🦀 Rust

A simple image average color extractor written in ?? Rust

Victor Aremu 3 Sep 23, 2021
A simple command-line utility (and Rust crate!) for converting from a conventional image file (e.g. a PNG file) into a pixel-art version constructed with emoji

EmojiPix This is a simple command-line utility (and Rust crate!) for converting from a conventional image file (e.g. a PNG file) into a pixel-art vers

Michael Milton 22 Dec 6, 2022
A Simple Image to Ascii converter in Rust

Image to Ascii A Simple Image to Ascii converter in Rust Brief ?? In my way to learn Rust i decided to make this converter. Challenges ?? new to Rust

WasixXD 7 Sep 16, 2022
Rust port of the Quite Okay Image format

qoi_rs What is this? A pretty boring Rust translation of qoi. Status What's there Encode & Decode works Results agree with the C implementation for al

null 9 Dec 9, 2021
A Rust encoder/decoder for Dominic Szablewski's QOI format for fast, lossless image compression.

QOI - The “Quite OK Image” format This is a Rust encoder and decoder for Dominic Szablewski's QOI format for fast, lossless image compression. See the

Chevy Ray Johnston 62 Nov 29, 2022
Rust based breadth first search maze image solver

maze_solver Rust based breadth first search maze image solver Works on black and white images with provided start and end points. Usage: maze_solver

null 0 Jan 31, 2022
Image processing operations

imageproc An image processing library, based on the image library. There may initially be overlap between the functions in this library and those in i

image-rs 512 Jan 8, 2023
Image Compression Algorithm

Image Compression Algorithm ?? A new lossless image compression algorithm. In the newest version the algorithm performs rather good, but manages to su

Hannes 31 May 10, 2022
Artsy pixel image to vector graphics converter

inkdrop inkdrop is an artsy bitmap to vector converter. Command line interface The CLI binary is called inkdrop-cli and reads almost any image bitmap

Matthias Vogelgesang 62 Dec 26, 2022
Automated image compression for efficiently distributing images on the web.

Imager Apparently this project made it into the GitHub Archive Program. About Imager is a tool for automated image compression, and can competitively

Imager IO 487 Dec 25, 2022
Open Graphic Image Writer

Open Graphic Image Writer Documentation You can generate Open Graphic Image dynamically. A CSS-like API. You can generate image by using template imag

keiya sasaki 46 Dec 15, 2022
Signed distance field font and image command line tool based on OpenCL.

SDFTool Signed distance field font and image command line tool based on OpenCL. Build Windows Run cargo build --release in Visual Studio developer x64

弦语蝶梦 7 Oct 16, 2022