jonathanong / identify

Image identification service with Vips via Sharp support falling back to ImageMagick

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@jongleberry/identify

Node.js CI codecov

A tiny image identification service:

  • Uses libvips via sharp if available
  • Falls back to ImageMagick
  • Errors if neither exist

API

const IdentifyService = require('@jongleberry/identify')

const identifyService = new IdentifyService({
  // defaults, no need to set these
  sharp: true,
  imagemagick: true, 
})

const filename = 'some-image.png'

try {
  const result = await identifyService.identify(filename)
  // ['imagemagick', {}]
  // ['sharp', {}]

  const metadata = await identifyService.normalize(result)
  // { width, height, ... }
} catch (err) {
  if (identifyService.isNotAnImageError(err)) throw new Error(`${filename} is not an image.`)
  throw err
}

About

Image identification service with Vips via Sharp support falling back to ImageMagick

License:MIT License


Languages

Language:JavaScript 94.9%Language:Shell 5.1%