Last active
May 17, 2020 07:55
-
-
Save andion/54c1d501b988b896eace2fcabe00441b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
sx, | |
sy, | |
sWidth, | |
sHeight, | |
dx, | |
dy, | |
dWidth, | |
dHeight, | |
canvasWidth, | |
canvasHeight, | |
} = getAspectRatioParams(originalWidth, originalHeight, transformedRatio, true); | |
canvas.width = canvasWidth; | |
canvas.height = canvasHeight; | |
// Create a rectangle with the desired background color the size of the canvas. | |
ctx.fillStyle = "#FE27FF"; | |
ctx.fillRect(0, 0, canvasWidth, canvasHeight); | |
// Now we can "paste" our cropped image on top | |
ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment