mirror of
https://github.com/nolanlawson/blob-util.git
synced 2025-12-08 19:46:19 +00:00
* remove jsdoc * move to esm * export arrayBufferToBinaryString and binaryStringToArrayBuffer * remove Promise polyfill * don't return Promises unnecessarily * add typescript/typedoc
37 lines
803 B
TypeScript
37 lines
803 B
TypeScript
// TODO: including these in blob-util.ts causes typedoc to generate docs for them,
|
|
// even with --excludePrivate ¯\_(ツ)_/¯
|
|
|
|
/** @private */
|
|
export function loadImage (src, crossOrigin) {
|
|
return new Promise(function (resolve, reject) {
|
|
var img = new Image()
|
|
if (crossOrigin) {
|
|
img.crossOrigin = crossOrigin
|
|
}
|
|
img.onload = function () {
|
|
resolve(img)
|
|
}
|
|
img.onerror = reject
|
|
img.src = src
|
|
})
|
|
}
|
|
|
|
/** @private */
|
|
export function imgToCanvas (img) {
|
|
var canvas = document.createElement('canvas')
|
|
|
|
canvas.width = img.width
|
|
canvas.height = img.height
|
|
|
|
// copy the image contents to the canvas
|
|
var context = canvas.getContext('2d')
|
|
context.drawImage(
|
|
img,
|
|
0, 0,
|
|
img.width, img.height,
|
|
0, 0,
|
|
img.width, img.height)
|
|
|
|
return canvas
|
|
}
|