From 504e9e2617a51ab60259df9771bd26084266d3e5 Mon Sep 17 00:00:00 2001 From: Modder4869 <28317935+Modder4869@users.noreply.github.com> Date: Wed, 12 Oct 2022 13:55:22 +0300 Subject: [PATCH] add new line , center image --- src/App.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/App.jsx b/src/App.jsx index fe01cc6..cb9e82c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -48,7 +48,14 @@ function App() { ctx.canvas.height = 256; if (loaded && document.fonts.check("12px YurukaStd")) { - ctx.drawImage(img, 0, 0, 296, 256); + //test 1 + var hRatio = ctx.canvas.width / img.width ; + var vRatio = ctx.canvas.height / img.height ; + var ratio = Math.min ( hRatio, vRatio ); + var centerShift_x = ( ctx.canvas.width - img.width*ratio ) / 2; + var centerShift_y = ( ctx.canvas.height - img.height*ratio ) / 2; +ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height); +ctx.drawImage(img, 0,0, img.width, img.height,centerShift_x,centerShift_y,img.width*ratio, img.height*ratio); ctx.font = `${fontSize}px YurukaStd`; ctx.lineWidth = 9; ctx.save();