Skip to content

Commit

Permalink
Merge pull request #257 from rokrak1/feature/canvas-draw-improvement
Browse files Browse the repository at this point in the history
Implemented width and height parameters in drawBlobOnCanvas function
  • Loading branch information
dgostencnik authored Jan 25, 2024
2 parents 4a38647 + c6f62a2 commit 20269a4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/utils/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { MimeType, ImageProperties } from '../layer/const';
export async function drawBlobOnCanvas(
ctx: CanvasRenderingContext2D,
blob: Blob,
x: number = 0,
y: number = 0,
dx: number = 0,
dy: number = 0,
dWidth?: number,
dHeight?: number,
): Promise<void> {
const objectURL = URL.createObjectURL(blob);
try {
Expand All @@ -15,7 +17,11 @@ export async function drawBlobOnCanvas(
img.onerror = reject;
img.src = objectURL;
});
ctx.drawImage(imgDrawn, x, y);

const width = dWidth ?? imgDrawn.naturalWidth;
const height = dHeight ?? imgDrawn.naturalHeight;

ctx.drawImage(imgDrawn, dx, dy, width, height);
} finally {
URL.revokeObjectURL(objectURL);
}
Expand Down

0 comments on commit 20269a4

Please sign in to comment.