fix: use sharp to convert svg to png, closes #13534

This commit is contained in:
Barış Soner Uşaklı
2025-07-25 10:49:52 -04:00
parent 5a86415092
commit b74c789849
2 changed files with 4 additions and 5 deletions

View File

@@ -35,7 +35,6 @@
"@isaacs/ttlcache": "1.4.1",
"@nodebb/spider-detector": "2.0.3",
"@popperjs/core": "2.11.8",
"@resvg/resvg-js": "2.6.2",
"@textcomplete/contenteditable": "0.1.13",
"@textcomplete/core": "0.1.13",
"@textcomplete/textarea": "0.1.13",

View File

@@ -5,7 +5,7 @@ const fs = require('fs/promises');
const nconf = require('nconf');
const winston = require('winston');
const { default: satori } = require('satori');
const { Resvg } = require('@resvg/resvg-js');
const sharp = require('sharp');
const utils = require('../utils');
@@ -96,9 +96,9 @@ Icons.regenerate = async (cid) => {
await fs.writeFile(path.resolve(nconf.get('upload_path'), 'category', `category-${cid}-icon.svg`), svg);
// Generate and save PNG
const resvg = new Resvg(Buffer.from(svg));
const pngData = resvg.render();
const pngBuffer = pngData.asPng();
const pngBuffer = await sharp(Buffer.from(svg))
.png()
.toBuffer();
await fs.writeFile(path.resolve(nconf.get('upload_path'), 'category', `category-${cid}-icon.png`), pngBuffer);