Add inline svg metadata

This commit is contained in:
Nicholas Jitkoff 2023-02-10 07:14:40 -07:00
parent 47a21f4e0c
commit 6b45bc13bf
2 changed files with 20 additions and 1 deletions

18
functions/rasterize.js Normal file
View file

@ -0,0 +1,18 @@
const sharp = require("sharp")
exports.handler = async function (event, context) {
console.log("event", event, context, event.rawQuery);
let data = event.rawQuery.replace(/\=/g,'')
let svg = atob(data) || decodeURIComponent(event.rawQuery);
if (!svg.startsWith("<svg")) svg = `<svg xmlns="http://www.w3.org/2000/svg">${svg}</svg>`
console.log("svg", svg)
const img = sharp(Buffer.from(svg))
.resize(1200)
const jpeg = img.jpeg().toBuffer();
return {
statusCode: 200,
headers: {"content-type": "image/jpeg"},
isBase64Encoded: true,
body: (await jpeg).toString('base64')
};
};

View file

@ -1,6 +1,7 @@
{
"dependencies": {
"brotli-wasm": "^1.1.0"
"brotli-wasm": "^1.1.0",
"sharp": "^0.31.3"
},
"devDependencies": {
"netlify-cli": "^11.5.1"