diff --git a/action.yml b/action.yml index b4211933..9f048254 100644 --- a/action.yml +++ b/action.yml @@ -52,6 +52,12 @@ inputs: description: Enable or disable SVG animations default: yes + # Add bottom padding + # This can used to add padding if generated image is cropped or on the contrary, remove empty space + config_padding: + description: Configure bottom padding + default: 20 + # Number of repositories to use for metrics # A high number increase metrics accuracy, but will consume additional API requests when using plugins repositories: diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index c4d3c494..4afb95b3 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -113,10 +113,12 @@ "config.timezone":input.string("config_timezone"), "config.output":input.string("config_output"), "config.animations":input.bool("config_animations"), + "config.padding":input.number("config_padding"), } info("Timezone", config["config.timezone"] ?? "(system default)") info("Convert SVG", config["config.output"] ?? "(no)") info("Enable SVG animations", config["config.animations"]) + info("SVG bottom padding", config["config.padding"]) //Additional plugins const plugins = { diff --git a/source/app/metrics.mjs b/source/app/metrics.mjs index 1472d011..9ef205ad 100644 --- a/source/app/metrics.mjs +++ b/source/app/metrics.mjs @@ -84,7 +84,7 @@ console.debug(`metrics/compute/${login} > render`) let rendered = await ejs.render(image, {...data, s, style, fonts}, {async:true}) //Apply resizing - const {resized, mime} = await svgresize(rendered, {convert}) + const {resized, mime} = await svgresize(rendered, {padding:"config.padding" in q ? Number(q["config.padding"]) : undefined, convert}) rendered = resized //Additional SVG transformations @@ -180,7 +180,7 @@ } /** Render svg */ - async function svgresize(svg, {convert} = {}) { + async function svgresize(svg, {padding = 10, convert} = {}) { //Instantiate browser if needed if (!svgresize.browser) { svgresize.browser = await puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]}) @@ -190,14 +190,14 @@ const page = await svgresize.browser.newPage() await page.setContent(svg, {waitUntil:"load"}) let mime = "image/svg+xml" - let {resized, width, height} = await page.evaluate(async () => { + let {resized, width, height} = await page.evaluate(async padding => { //Disable animations const animated = !document.querySelector("svg").classList.contains("no-animations") if (animated) document.querySelector("svg").classList.add("no-animations") //Get bounds and resize let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect() - height = Math.ceil(height) + height = Math.ceil(height + padding) width = Math.ceil(width) //Resize svg document.querySelector("svg").setAttribute("height", height) @@ -206,7 +206,7 @@ document.querySelector("svg").classList.remove("no-animations") //Result return {resized:new XMLSerializer().serializeToString(document.querySelector("svg")), height, width} - }) + }, padding) //Convert if required if (convert) { console.debug(`metrics/svgresize > convert to ${convert}`)