1
0
Fork 0
mirror of https://github.com/voltbonn/profile-picture-generator.git synced 2024-12-22 07:45:04 +00:00

corrected the image fitting to cover the frame-area

This commit is contained in:
thomasrosen 2021-01-21 20:57:03 +01:00
parent 2dd926cbbb
commit 5c358d7d53

View file

@ -27,10 +27,17 @@ function App() {
offscreenCanvas.width = frameSize
offscreenCanvas.height = frameSize
const width = frameSize
const height = (img.height / img.width) * frameSize
const offscreenCanvas_ctx = offscreenCanvas.getContext('2d', { alpha: true })
let width, height;
if (img.width < img.height) {
height = (img.height / img.width) * frameSize
width = frameSize
} else {
height = frameSize
width = (img.width / img.height) * frameSize
}
offscreenCanvas_ctx.drawImage(
img,
(frameSize - width) / 2,