image

module:image

Description:
  • Scaling and composing images with Sharp.js

Source:

Methods

(async, static) image.composite(items, defaultsopt) → {Array.<object>}

Description:
  • Blend multiple images together, first image is used as the background for remaning items

Source:
Parameters:
Name Type Attributes Description
items Array.<object>

list of objects representing an image or text, properties are given to module:image.create, additional string property id can be used to describe or distinguish items from each other

defaults object <optional>

defaults global for all items, same parameters

Returns:
Type Description
Array.<object>
  • same items list with additional properties: buffer, meta

(static) image.convert(input, item) → {object}

Description:
  • Apply Sharp image filters and conversions

Source:
Parameters:
Name Type Description
input object

sharp image

item object
Properties
Name Type Attributes Description
filters Array.<object> <optional>

filters, each operation must provide filter name and value as a map or an object

Returns:
Type Description
object

transformed image

(async, static) image.create(item) → {Promise}

Description:
  • Create an image from a photo or text, supports raunded corners, borders

Source:
Parameters:
Name Type Description
item object
Properties
Name Type Attributes Default Description
file string | Buffer <optional>

input file name

data Buffer | string <optional>

image buffer or data:image/*;base64, takes precedence over file name

width int <optional>

desired width, max width for text

height int <optional>

desired height, defaults to width if not given

background string <optional>
#FFFFFF

main background color

border int <optional>

border size in px

border_color string <optional>
FFFFFFF0

border color

border_radius number <optional>

make border round, this is divider of the size

padding number <optional>

transparent padding around image

padding_x number <optional>
padding_y number <optional>
padding_top number <optional>
padding_bottom number <optional>
padding_left number <optional>
padding_right number <optional>
padding_color int <optional>

padding background color

padding_radius number <optional>

make padding round

fit string <optional>

resize mode

position string <optional>
kernel string <optional>
gravity string <optional>
withoutEnlargement boolean <optional>
withoutReduction boolean <optional>
fastShrinkOnLoad boolean <optional>
radius number <optional>

make it round, inner and outer layers, this is divider of the size

text string <optional>

text to render

color string <optional>

text color

alpha string <optional>

text opacity 0-65535 or 50%

bgalpha string <optional>

text background opacity 0-65535 or 50%

font string <optional>

font family

fontfile string <optional>

font file

weight string <optional>

One of ultralight, light, normal, bold, ultrabold, heavy, or a numeric weight.

size string <optional>

font size in 1024ths of a point, or in points (e.g. 12.5pt), or one of the absolute sizes xx-small, x-small, small, medium, large, x-large, xx-large, or a percentage (e.g. 200%), or one of the relative sizes smaller or larger.

stretch string <optional>

One of ultracondensed, extracondensed, condensed, semicondensed, normal, semiexpanded, expanded, extraexpanded, ultraexpanded.

style string <optional>

One of normal, oblique, italic.

spacing int <optional>

font spacing

dpi int <optional>
72

text size in DPI

justify boolean <optional>
true

text justification

wrap string <optional>

text wrapping if width is provided: word, char, word-char, none

align string <optional>

text aligment: left, centre, center, right

blend string <optional>

how to blend image, one of clear, source, over, in, out, atop, dest, dest-over, dest-in, dest-out, dest-atop, xor, add, saturate, multiply, screen, overlay, darken, lighten, colour-dodge, color-dodge, colour-burn,color-burn, hard-light, soft-light, difference, exclusion.

sharp object <optional>

additional raw Sharp item

Returns:
Type Description
Promise
  • a sharp object containing an image, as PNG

(static) image.createGradient(item) → {Buffer}

Description:
  • Generate an SVG radial-gradient ellipse overlay for an image item and return it as a Buffer.

    Picks a gradient color (gcolor) based on item.color and item.gradient_type, adjusting for luminance/contrast, then builds an SVG sized to item.meta.width/item.meta.height.

Source:
Parameters:
Name Type Description
item Object
Properties
Name Type Attributes Default Description
_meta Object
Properties
Name Type Description
width number

SVG width in pixels.

height number

SVG height in pixels.

color string <optional>
"#fff"

Base color in hex format.

_color string <optional>
"#fff"

Detected color in hex format.

gradient_type string <optional>

Gradient mode, e.g. "mid" (default uses negate).

id string | number <optional>

Identifier used for debug logging.

Returns:
Type Description
Buffer

SVG markup as a Buffer.

(async, static) image.detect(item, bgimage)

Description:
  • Detect a text color to place on top of the area inside given background

Source:
Parameters:
Name Type Description
item object

input item

bgimage object

Sharp image with background

(static) image.gravityRegion(gravity, width, height) → {object}

Description:
  • Return region corresponding to the gravity

Source:
Parameters:
Name Type Description
gravity string
width int
height int
Returns:
Type Description
object
  • object { left, top, width, height }

(static) image.mergeDefaults(item, defaultsopt) → {object}

Description:
  • Merge defaults into an item, supports format id.name or type.name where id must match item.id and type item.type

Source:
Parameters:
Name Type Attributes Description
item object
defaults object <optional>
Returns:
Type Description
object

(static) image.padding(itemopt) → {Object}

Description:
  • Normalize padding-related item into a rectangle object.

    Accepts either side-specific padding values or axis-wide or single padding:

    • padding_top, padding_right, padding_bottom, padding_left (highest priority)
    • padding_y applies to top/bottom, padding_x applies to left/right
    • padding applies to all sides

    Missing/undefined values are coerced via lib.toNumber(...).

Source:
Parameters:
Name Type Attributes Description
item object <optional>

Input item object.

Properties
Name Type Attributes Description
padding number | string <optional>

Padding for all sides.

padding_x number | string <optional>

Padding for left/right.

padding_y number | string <optional>

Padding for top/bottom.

padding_top number | string <optional>

Padding for top side.

padding_right number | string <optional>

Padding for right side.

padding_bottom number | string <optional>

Padding for bottom side.

padding_left number | string <optional>

Padding for left side.

Returns:
Type Description
Object

Padding rectangle.

(static) image.stats(input, regionopt) → {object}

Description:
  • Return the stats about given region with inverted dominant color, if no region provided stats for the whole image

Source:
Parameters:
Name Type Attributes Description
input Buffer | object

buffer or sharp object

region object <optional>

region to extract and return stats for

Returns:
Type Description
object

region stats with additional properties:

  • dominant - dominant color
  • mean - mean color as RGB
  • meta - meta data object
  • image - image as hidden property