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

context.drawImage() does not respect sy parameter when scaled #2397

Closed
1 task done
jejebecarte opened this issue Jul 13, 2024 · 1 comment
Closed
1 task done

context.drawImage() does not respect sy parameter when scaled #2397

jejebecarte opened this issue Jul 13, 2024 · 1 comment

Comments

@jejebecarte
Copy link

jejebecarte commented Jul 13, 2024

Issue or Feature

When using context.drawImage() with a slice of an image as the source, and then scaling the result up occasionally results in areas outside the slice being included in the final output. Changing the scaling factor can change the position of or remove these issues. (Try a scaling factor of 24 or 30 in the example below and see how the issue goes away).

In this example, the expected output vs. actual output (notice the 1px line at the top, which is from the character above in the supplied sprite sheet):
df36
df36

While I'm not able to verify this, I think the entire imaged might be shifted by 1px when this artifact is included.

Also note that many, but not all characters experience this issue. Some include lines on the bottom and others on the top.

Steps to Reproduce

Place the nonlatin_european.png in the directory and run the following code:

const fs = require('fs');
const path = require('path');
const { createCanvas, Image } = require('canvas');

const SCALING = 27;
const SIDE_LENGTH = 8;

const image = new Image();
image.onload = () => {
    const canvas = createCanvas(250, 250);
    const ctx = canvas.getContext('2d');

    ctx.imageSmoothingEnabled = false;
    ctx.drawImage(
        image,
        15 * SIDE_LENGTH, // This is \udf36
        61 * SIDE_LENGTH, // This is \udf36
        SIDE_LENGTH,
        SIDE_LENGTH,
        0,
        0,
        SIDE_LENGTH * SCALING,
        SIDE_LENGTH * SCALING
    );

    canvas.createPNGStream().pipe(fs.createWriteStream(path.join(__dirname, 'df36.png')));
};

image.src = path.resolve(__dirname, 'nonlatin_european.png');

Your Environment

  • Version of node-canvas: 2.10.2
  • Environment: node v20.12.0 on Windows 10
@jejebecarte
Copy link
Author

Without changing anything, this issue has randomly resolved itself.

jejebecarte added a commit to jejebecarte/minecraft-text-canvas that referenced this issue Sep 27, 2024
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

No branches or pull requests

1 participant