Module: kongUtilImage

Methods

(inner) canvasTo(canvas, returnType) → {Promise.<*>}

Parameters:
Name Type Description
canvas HTMLCanvasElement
returnType string

bitmap, blob, dataURL, or canvas

Source:
Returns:
Type
Promise.<*>

(inner) readImage(source, optionopt, optionopt) → {Promise.<ImageBitmap>}

Support more than createImageBitmap().

Parameters:
Name Type Attributes Description
source *

string and those supported by createImageBitmap() in Web API

option string <optional>

used only if source is pure base64 string (instead of dataURL)

option Object <optional>

passed as the 2nd argument of fetch()

Source:
Returns:
Type
Promise.<ImageBitmap>

(inner) resizeImage(source, settings) → {Promise.<*>}

Load and resize an image to specified format.

Safari does not support options.resize* in createImageBitmap(); therefore we must draw the bitmap to canvas, instead of resizing it by calling creatImageBitmap().

Parameters:
Name Type Description
source *
settings Object
Properties
Name Type Attributes Default Description
scale number <optional>

conflicts with width and height

width number <optional>

conflicts with scale

height number <optional>

conflicts with scale

fit string <optional>
contain

fill, contain, cover, scaleDown. Only useful if both width and height are given.

format string <optional>
image/png

MIME

quality number <optional>

between 0 and 1

returnType string <optional>
canvas

canvas, blob, or dataURL

Source:
Returns:
Type
Promise.<*>
Example
/// resize the chosen file and then show it
    resizeImage($('[type=file]').files[0], {scale: .5, returnType: 'dataURL'})
    .then(url => location = url);