diff --git a/src/serve_rendered.js b/src/serve_rendered.js index fc9982f..ecb1b53 100644 --- a/src/serve_rendered.js +++ b/src/serve_rendered.js @@ -771,6 +771,26 @@ export const serve_rendered = { composite_array.push({ input: canvas.toBuffer() }); } + if (item.attributionText) { + const canvas = createCanvas(scale * width, scale * height); + const ctx = canvas.getContext('2d'); + ctx.scale(scale, scale); + + ctx.font = '12px sans-serif'; + const text = item.attributionText; + const textMetrics = ctx.measureText(text); + const textWidth = textMetrics.width; + const textHeight = 14; + + const padding = 10; + ctx.fillStyle = 'rgba(255, 255, 255, 0.8)'; + ctx.fillRect(width - textWidth - padding, height - textHeight - padding, textWidth + padding, textHeight + padding); + ctx.fillStyle = 'rgba(0,0,0,.8)'; + ctx.fillText(item.attributionText, width - textWidth - (padding / 2), height - textHeight + 8); + + composite_array.push({ input: canvas.toBuffer() }); + } + if (composite_array.length > 0) { image.composite(composite_array); } @@ -1378,6 +1398,7 @@ export const serve_rendered = { dataProjWGStoInternalWGS: null, lastModified: new Date().toUTCString(), watermark: params.watermark || options.watermark, + attributionText: params.attributionText || options.attributionText, }; repo[id] = repoobj;