src/utils.js
/**
 * Scales an image at a given scale and near power of two scale into a returned
 * canvas DOM element.
 * scaleImageIntoCanvas(image: HTMLImageElement,
 *                      scale: HTMLCanvasElement,
 *                      scaleNearestPowerOfTwo: Number) -> HTMLCanvasElement
 */
Scales an image at a given scale and near power of two scale into a returned
canvas DOM element.
Scales an image at a given scale and near power of two scale into a returned canvas DOM element .
function scaleImageIntoCanvas(image, scale, scaleNearestPowerOfTwo) {
  const canvas = createCanvas()
  const context = canvas.getContext('2d')
  let {width, height} = image
  if (scaleNearestPowerOfTwo) {
    width = nearestPowerOfTwo(width)
    height = nearestPowerOfTwo(height)
  }
  canvas.width = Math.floor(image.width * scale)
  canvas.height = Math.floor(image.height * scale)
  context.drawImage(image, 0,0, width, height, 0,0, canvas.width, canvas.height)
  return canvas
}
function scaleImageIntoCanvas ( image , scale , scaleNearestPowerOfTwo ) { const canvas = createCanvas ( ) const context = canvas . getContext ( '2d' ) let { width , height } = image if ( scaleNearestPowerOfTwo ) { width = nearestPowerOfTwo ( width ) height = nearestPowerOfTwo ( height ) } canvas . width = Math . floor ( image . width * scale ) canvas . height = Math . floor ( image . height * scale ) context . drawImage ( image , 0 , 0 , width , height , 0 , 0 , canvas . width , canvas . height ) return canvas }
Scales an image at a given scale and near power of two scale into a returned
 canvas DOM element.
Scales an image at a given scale and near power of two scale into a returned canvas DOM element .