Skip to content

Commit 3aef7fb

Browse files
authored
Merge pull request #4 from nextml-code/fix-draw-image-no-dimension
fix: drawImage(image, x, y) ignored scale
2 parents 5cc0b32 + 61b5de9 commit 3aef7fb

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

example/example.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,20 @@ const contextFar = getFarContext2d(document.getElementById("far"), {
7070

7171
image.data.onload = function () {
7272
function render(ctx) {
73-
images.forEach((image) => {
73+
images.forEach((image, i) => {
7474
ctx.save();
7575

76-
ctx.drawImage(image.data, image.x, image.y, image.width, image.height);
76+
if (i == 1) {
77+
ctx.drawImage(image.data, image.x, image.y);
78+
} else {
79+
ctx.drawImage(
80+
image.data,
81+
image.x,
82+
image.y,
83+
image.width - i * 32,
84+
image.height
85+
);
86+
}
7787
ctx.beginPath();
7888
ctx.strokeStyle = "#803";
7989
ctx.lineWidth = 1;

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,13 @@ const getFarContext2d = (canvas, { x = 0, y = 0, scale = 1 } = {}) => {
295295
drawImage(image, ...args) {
296296
if (args.length === 2) {
297297
const [dx, dy] = args;
298-
return _context.drawImage(image, s.x(dx), s.y(dy));
298+
return _context.drawImage(
299+
image,
300+
s.x(dx),
301+
s.y(dy),
302+
s.distance(image.width),
303+
s.distance(image.height)
304+
);
299305
} else if (args.length === 4) {
300306
const [dx, dy, dWidth, dHeight] = args;
301307
return _context.drawImage(

0 commit comments

Comments
 (0)