1.2.0 • Published 2 months ago

visionary-url v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

Visionary URL is a lightweight Typescript library for generating image URLs with built-in Blurhash placeholders.

NPM version GitHub Actions Workflow Status NPM bundle size

Getting started

Install visionary-url via npm. Both ES modules and CommonJS modules are supported.

npm install --save visionary-url

Generating a Visionary URL

import { generateVisionaryUrl } from 'visionary-url';

const url = generateVisionaryUrl({
  blurhash: "LCDJYN9FxG_M_N%L%M%M4o~ptRIA", // blurhash string
  blurhashX: 4, // blurhash x components
  blurhashY: 4, // blurhash y components
  bcc: "#baccae", // background color code
  fileId: "image:101", // image ID or URL
  sourceHeight: 1200, // image height
  sourceWidth: 1600, // image width
});

How it works

A Visionary URL is formatted using 3 or 4 URL segments: | | base path | | visionary code | | options (optional) | | filename | | -- | -- | -- | -- | -- | -- | -- | -- | | / | image | / | <visionary code, base64url> | / |<option tokens> | / | image.jpg |

Example URLs

https://examplecdn.cloud/image/aW1hZ2U6MTAwMDEhODAwITYwMA/image.jpg
https://examplecdn.cloud/image/aW1hZ2U6MTAwMDEhODAwITYwMA/4k/image.jpg

Visionary code

The Visionary code is a base64url'd, exclamation-point separated list of image placeholder data, detailed as the following:

AttributeDescription
Image IDImage URL or internal image ID (required)
Image widthUsed to compute aspect ratio of image placeholder (required)
Image heightUsed to compute aspect ratio of image placeholder (required)
Background color codeBase layer background color code (e.g. #BACCAE)
Blurhash codeBlurhash string of the image
Blurhash x componentsNumber of x components the blurhash code represents
Blurhash y componentsNumber of y components the blurhash code represents

Image options

Image options are optional and are provided as comma separated tokens.

Size token

One of the following tokens may be included in the options string to specify an image size: xs, sm, md, lg, xl, xxl, 4k, 5k

Download token

tokendescription
downloadIndication for server to return content-disposition: attachment; in response headers
1.2.0

2 months ago

1.1.6

2 months ago

1.1.5

2 months ago

1.1.4

3 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.1.0

4 months ago

1.0.8

5 months ago