Builds resized image URLs on the Lynkow image transformation service, accessible via lynkow.media. It makes no request and works on the server and in the browser. It accepts original Lynkow media URLs and URLs it already transformed.

Access via: lynkow.media

Methods

2 methods

srcset

TypeScript
srcset(imageUrl: string | null | undefined, options: SrcsetOptions): string

Builds a srcset attribute value from a Lynkow image URL, with one transformed URL per width. Returns an empty string for null, undefined or a URL that is not a Lynkow media URL.

Parameter

Type

Description

imageUrl

string | null | undefined

Image URL from the API, such as content.featuredImage

options

SrcsetOptions

widths, fit, quality and gravity, see SrcsetOptions

Returns: string

TypeScript
const srcset = lynkow.media.srcset(article.featuredImage, { widths: [480, 960], fit: 'cover' })
const img = `<img src="${article.featuredImage}" srcset="${srcset}" sizes="100vw" alt="" />`

transform

TypeScript
transform(imageUrl: string | null | undefined, options: TransformOptions): string

Builds one transformed URL from a Lynkow image URL, for a thumbnail or any fixed size. Returns a URL that is not a Lynkow media URL unchanged, and an empty string for null or undefined.

Parameter

Type

Description

imageUrl

string | null | undefined

Image URL from the API, such as content.featuredImage

options

TransformOptions

Size, fit, format, quality, gravity and dpr, see TransformOptions

Returns: string

TypeScript
const thumb = lynkow.media.transform(content.featuredImage, { w: 400, h: 300, fit: 'cover' })