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

fix: background images should not be blurry in export #3101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/render/canvas/canvas-renderer.ts
Expand Up @@ -600,11 +600,20 @@ export class CanvasRenderer extends Renderer {
image.height,
image.width / image.height
]);
const pattern = this.ctx.createPattern(
this.resizeImage(image, width, height),
'repeat'
) as CanvasPattern;
this.renderRepeat(path, pattern, x, y);
const scaleX = width / image.naturalWidth;
const scaleY = height / image.naturalHeight;
const pattern = this.ctx.createPattern(image, 'repeat') as CanvasPattern;
const scaledPath = (path as Vector[]).map((item) => {
item.x = item.x / scaleX;
item.y = item.y / scaleY;
return item;
});
const scaledOffsetX = x / scaleX;
const scaledOffsetY = y / scaleY;
this.ctx.save();
this.ctx.scale(scaleX, scaleY);
this.renderRepeat(scaledPath, pattern, scaledOffsetX, scaledOffsetY);
this.ctx.restore();
}
} else if (isLinearGradient(backgroundImage)) {
const [path, x, y, width, height] = calculateBackgroundRendering(container, index, [null, null, null]);
Expand Down