npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

bare-media

1.8.0

@educastellano

npmSnykSocket
Downloads:689
$ npm install bare-media
DailyWeeklyMonthlyYearly

bare-media

A set of media apis for Bare

Install

npm i bare-media

Usage

From a single worker:

import worker from 'bare-media'

const data = await worker.createPreview({ path, maxWidth, maxHeight })

Manually instantiate one or multiple workers:

import { WorkerClient } from 'bare-media/client'

const worker = new WorkerClient()
const data = await worker.createPreview({ path, maxWidth, maxHeight })

NOTE: A worker spawns when an operation is requested and it stays running until the parent process is killed.

Terminate the worker:

worker.close()

worker.onClose = () => {
  // worker terminated
}

Call the methods directly without a worker:

import { createPreview } from 'bare-media/worker/media.js'

const data = await createPreview({ path, maxWidth, maxHeight })

API

See schema.js for the complete reference of parameters

createPreview()

Create a preview from a media file

PropertyTypeDescription
pathstringPath to the input file. Either path, httpLink or buffer is required
httpLinkstringHttp link to the input file
bufferobjectBytes of the input file
mimetypestringMedia type of the input file. If not provided it will be detected
maxWidthnumberMax width for the generated preview
maxHeightnumberMax height for the generated preview
maxFramesnumberMax frames for the generated preview in case the file is animated
maxBytesnumberMax bytes for the generated preview
formatstringMedia type for the generated preview. Default image/webp
encodingstringbase64 or nothing for buffer

decodeImage()

Decode an image to RGBA

PropertyTypeDescription
pathstringPath to the input file. Either path, httpLink or buffer is required
httpLinkstringHttp link to the input file
bufferobjectBytes of the input file
mimetypestringMedia type of the input file. If not provided it will be detected

cropImage()

Crop an image

PropertyTypeDescription
pathstringPath to the input file. Either path, httpLink or buffer is required
httpLinkstringHttp link to the input file
bufferobjectBytes of the input file
mimetypestringMedia type of the input file. If not provided it will be detected
leftnumberOffset from left edge
topnumberOffset from top edge
widthnumberWidth of the region to crop
heightnumberHeight of the region to crop
formatstringMedia type for the cropped image. Default same as the input image

License

Apache-2.0