src/utils.js
/**
 * Converts an input image or canvas to a power of two image.
 * makePowerOfTwo(image: HTMLCanvasElement|HTMLImageElement) -> HTMLImageElement|HTMLCanvasElement
 */
Converts an input image or canvas to a power of two image.
Converts an input image or canvas to a power of two image .
function makePowerOfTwo(image) {
	if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement) {
		const canvas = createCanvas()
		const context = canvas.getContext('2d')
		canvas.width = nearestPowerOfTwo(image.width)
		canvas.height = nearestPowerOfTwo(image.height)
		context.drawImage(image, 0, 0, canvas.width, canvas.height)
		return canvas
	}
	return image
}
function makePowerOfTwo ( image ) { if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) { const canvas = createCanvas ( ) const context = canvas . getContext ( '2d' ) canvas . width = nearestPowerOfTwo ( image . width ) canvas . height = nearestPowerOfTwo ( image . height ) context . drawImage ( image , 0 , 0 , canvas . width , canvas . height ) return canvas } return image }
Converts an input image or canvas to a power of two image.
Converts an input image or canvas to a power of two image .