From e6cba03ecd2477e1717a4227eb9727eea1d461eb Mon Sep 17 00:00:00 2001 From: Natalia Platova Date: Wed, 16 Aug 2023 19:56:37 +0300 Subject: [PATCH 1/2] 5 corrected image sizes --- src/components/SetGridButton.vue | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/components/SetGridButton.vue b/src/components/SetGridButton.vue index 629e0d8..b550348 100644 --- a/src/components/SetGridButton.vue +++ b/src/components/SetGridButton.vue @@ -11,6 +11,7 @@ :class="animation ? 'canvas img_hidden' : 'canvas'" ref="canvasRef" > +
Date: Mon, 21 Aug 2023 12:07:02 +0300 Subject: [PATCH 2/2] resolve #5 5 corrected sizes --- src/components/SetGridButton.vue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/SetGridButton.vue b/src/components/SetGridButton.vue index b550348..e15d9cc 100644 --- a/src/components/SetGridButton.vue +++ b/src/components/SetGridButton.vue @@ -94,17 +94,19 @@ export default class SetGridButton extends Vue.with(Props) { img.src = url; img.onload = function () { const ratio = img.naturalWidth / img.naturalHeight; - const newWidth = containerHeight * ratio; - const newHeight = containerHeight; + const newWidth = containerHeight * ratio; + + const finalWidth = newWidth>containerWidth? containerWidth : newWidth; + const finalHeight = finalWidth / ratio; - const xOffset = (canvas.width - newWidth) / 2; - const yOffset = (canvas.height - newHeight) / 2; + const xOffset = (canvas.width - finalWidth) / 2; + const yOffset = (canvas.height - finalHeight) / 2; const ctx = canvas.getContext("2d"); // @ts-ignore ctx.clearRect(0, 0, canvas.width, canvas.height); // @ts-ignore - ctx.drawImage(img, xOffset, yOffset, newWidth, newHeight); + ctx.drawImage(img, xOffset, yOffset, finalWidth, finalHeight); }; }