Arrow keys: ← previous · → next 8 of 35
@nodedk/image
0.1.4 stable

image#

Retouch image files with Jimp and read metadata with ExifTool.

Requirements#

retouch uses Jimp’s legacy decoders, positional method arguments, AUTO, and writeAsync API. The declared Jimp 1.x dependency does not expose that API, so the current package needs a compatibility update before use. info additionally requires exiftool on PATH.

Install#

npm i @nodedk/image

Usage#

The API expects local file records and an ordered map of Jimp operations:

var image = require('@nodedk/image')

async function main() {
  var files = [{ name: 'photo.jpg', path: './photo.jpg' }]
  var config = {
    resize: [120, 120],
    greyscale: []
  }

  var result = await image.retouch(files, config)
  console.log(result[0].size)
  console.log(image.info('./photo.jpg'))
}

main().catch(console.error)

retouch(files, config)#

Returns a Promise of the processed file records, or undefined when no supported images are present.

  • files: array of objects with name and path. Supported extensions are .gif, .jpg, .jpeg, .tiff, .png, and .bmp, case-insensitively.
  • config: Jimp method names mapped to argument arrays, applied in object order. An empty array calls a method without arguments. The string 'auto' is replaced with Jimp.AUTO throughout the configuration, in place.

Images overwrite their source paths. Each processed record’s size is updated to its new byte count. Read, transform, and write errors reject.

info(path)#

Runs ExifTool synchronously and returns metadata as an object of strings. Keys are lowercased, with the first whitespace character replaced by _. Unsupported extensions return {}. ExifTool failures throw.

The path is interpolated into a shell command; use trusted paths without shell metacharacters.

Created by Vidar Eldøy