Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drawImage() regression in 0.1.66 - images not resizing #987

Closed
monteslu opened this issue Feb 3, 2025 · 1 comment · Fixed by #989
Closed

drawImage() regression in 0.1.66 - images not resizing #987

monteslu opened this issue Feb 3, 2025 · 1 comment · Fixed by #989

Comments

@monteslu
Copy link

monteslu commented Feb 3, 2025

Here's a test case using this cat picture:

Image

const { promises } = require('node:fs')
const { join } = require('node:path')
const { createCanvas, loadImage } = require('@napi-rs/canvas')

const backCanvas = createCanvas(1920, 1080);
const backCtx = backCanvas.getContext('2d');

const picCanvas = createCanvas(640, 480);
const picCtx = picCanvas.getContext('2d');


async function main() {
  backCtx.fillStyle = '#000000';
  backCtx.fillRect(0, 0, 1920, 1080);

  // load images from disk or from a URL
  const catImage = await loadImage('cat_640x480.jpg');

  picCtx.drawImage(catImage, 0, 0, catImage.width, catImage.height)

  backCtx.drawImage(picCanvas, 240, 0, 1440, 1080);

  // export canvas as image
  const pngData = await backCanvas.encode('png');
  await promises.writeFile(join(__dirname, 'stretched-cat.png'), pngData);
}

main();

In 0.1.65 this correctly produces:

Image

however in 0.1.66 it produces:

Image

This is also a bug when using the resizing parameters in context.putImageData()

@monteslu
Copy link
Author

monteslu commented Feb 3, 2025

also, this is just a canvas-on-canvas and putImageData issue. Drawing an actual image on a canvas stretches fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant