From 5c358d7d5327e96ca364a50679a44b5bd73c5486 Mon Sep 17 00:00:00 2001 From: thomasrosen Date: Thu, 21 Jan 2021 20:57:03 +0100 Subject: [PATCH] corrected the image fitting to cover the frame-area --- src/App.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index 8d24763..675f343 100644 --- a/src/App.js +++ b/src/App.js @@ -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,