mirror of
https://github.com/arfct/itty-bitty.git
synced 2026-03-11 08:54:33 +00:00
Add inline svg metadata
This commit is contained in:
parent
47a21f4e0c
commit
6b45bc13bf
2 changed files with 20 additions and 1 deletions
18
functions/rasterize.js
Normal file
18
functions/rasterize.js
Normal 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')
|
||||
};
|
||||
};
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue