Class: ImageTools

.utils.ImageTools()

Static class with image related utilities.

Constructor

new ImageTools()

Author:
Source:

Methods

(static) createImageDataUrl(width, height, color)

Creates a monochrome image and return its data URL. Note: const img = new Image(width, height); img.src = createImageDataUrl(width, height, color);
Parameters:
Name Type Description
width number Image width.
height number Image height.
color string Image color, e.g., "#0f1234" or "rgba(0,0,0,0)".
Source:

(static) improveLightboxPerformance(src, srcset) → {Array}

Apply browser dependent srcset restrictions that cause bad performance in the pswp lightbox.
Parameters:
Name Type Description
src string Image url.
srcset string Image srcset attribute with width descriptor.
Source:
Returns:
[src, srcset]
Type
Array

(static) srcsetSelector(srcset, width) → {Array}

Select the matching resolution for a given width from an image srcset attribute containing width descriptors. Reproduces the behavior of selecting an image with the srcset attribute.
Parameters:
Name Type Description
srcset string Srcset, i.e., "https://.../image1.jpg 720w, https://.../image2.jpg 1920w, https://.../image3.jpg 3840w".
width string | Number Width in pixel i.e., "1800".
Source:
Returns:
List containing matching url and descriptor, i.e., ["https://.../image2.jpg", "1920w"].
Type
Array