Skip to main content

image-utils@1.0.1

compress(base64ImgOrBuffer, [options])
embedMetadata(base64ImgOrBuffer, exifObj, [options])
metadata(base64ImgOrBuffer)
resize(base64ImgOrBuffer, [options])
stripMetadata(base64ImgOrBuffer, [options])

This adaptor exports the following from common:

as()
combine()
cursor()
dataPath()
dataValue()
dateFns
each()
field()
fields()
fn()
fnIf()
group()
http
lastReferenceValue()
map()
merge()
scrubEmojis()
sourceValue()
util

Functions

compress

compress(base64ImgOrBuffer, [options]) ⇒ Operation

Compress an image by reducing image quality until it reaches the criteria. Writes { buffer, size, quality } to state.data.

ParamTypeDefaultDescription
base64ImgOrBufferstring | Buffer | functionBase64 string, data URL, Buffer, or resolver fn
[options]object{}
[options.maxBytes]number716800Maximum output file size in bytes
[options.minQuality]number20JPEG quality floor (1–100); compression stops here even if maxBytes is not met
[options.parseAs]'buffer' | 'base64''buffer'Return format: 'buffer' (default) or 'base64'

This operation writes the following keys to state:

State KeyDescription
datathe result of the image operation
referencesan array of all previous data objects used in the Job

Example

compress(state.data.buffer, { maxBytes: 700 * 1024, minQuality: 20 })

embedMetadata

embedMetadata(base64ImgOrBuffer, exifObj, [options]) ⇒ Operation

Embed EXIF metadata into a JPEG image. Writes { buffer } to state.data.

ParamTypeDefaultDescription
base64ImgOrBufferstring | Buffer | functionBase64 string, data URL, Buffer, or resolver fn
exifObjobjectEXIF key-value pairs; keys must be valid EXIF tag names (e.g. UserComment, Make, Model)
[options]object{}
[options.parseAs]'buffer' | 'base64''buffer'Return format: 'buffer' (default) or 'base64'

This operation writes the following keys to state:

State KeyDescription
datathe result of the image operation
referencesan array of all previous data objects used in the Job

Example

embedMetadata($.data.buffer, { UserComment: 'patient-id=42' })
embedMetadata($.data.buffer, { UserComment: 'patient-id=42', Make: 'OpenFn' }, { parseAs: 'base64' })

metadata

metadata(base64ImgOrBuffer) ⇒ Operation

Read image metadata without modifying the image. Writes { width, height, orientation, size, exif } to state.data. exif is a flat object of human-readable EXIF tag names (e.g. { Make, Model, GPSLatitude, UserComment }). UserComment has the ASCII\0\0\0 encoding prefix stripped. Images with no EXIF return exif: {}.

ParamTypeDescription
base64ImgOrBufferstring | Buffer | functionBase64 string, data URL, Buffer, or resolver fn

This operation writes the following keys to state:

State KeyDescription
datathe result of the image operation
referencesan array of all previous data objects used in the Job

Example

metadata($.data.photoBase64)
fn(state => {
if (state.data.size > 700 * 1024) { ... }
return state;
})

resize

resize(base64ImgOrBuffer, [options]) ⇒ Operation

Resize an image to the given dimensions. Writes { buffer, width, height } to state.data.

ParamTypeDefaultDescription
base64ImgOrBufferstring | Buffer | functionBase64 string, data URL, Buffer, or resolver fn
[options]object{}
[options.width]numberOutput width in pixels
[options.height]numberOutput height in pixels
[options.parseAs]'buffer' | 'base64''buffer'Return format: 'buffer' (default) or 'base64'

This operation writes the following keys to state:

State KeyDescription
datathe result of the image operation
referencesan array of all previous data objects used in the Job

Example

resize($.data.photoBase64, { width: 1200, height: 1600 })

stripMetadata

stripMetadata(base64ImgOrBuffer, [options]) ⇒ Operation

Strip all EXIF metadata from an image. Output is always a JPEG buffer. Writes { buffer } to state.data.

ParamTypeDefaultDescription
base64ImgOrBufferstring | Buffer | functionBase64 string, data URL, Buffer, or resolver fn
[options]object{}
[options.parseAs]'buffer' | 'base64''buffer'Return format: 'buffer' (default) or 'base64'

This operation writes the following keys to state:

State KeyDescription
datathe result of the image operation
referencesan array of all previous data objects used in the Job

Example

stripMetadata($.data.photoBase64)