add support for stylized attribution text for static images
This commit is contained in:
parent
592beaab29
commit
7766ddbc03
1 changed files with 21 additions and 0 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue