Skip to content

Commit 8afe021

Browse files
Замена Resvg на sharp
1 parent d51e94d commit 8afe021

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

web/server/controllers/badgesController.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const pool = require('../config/database');
2-
const { Resvg } = require('@resvg/resvg-js');
2+
const sharp = require('sharp');
33

44
// SVG logo for badges
55
const logoSvg = '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="768px" height="768px" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" xmlns:xlink="http://www.w3.org/1999/xlink"> <g><path style="opacity:0.997" fill="#eaa708" d="M 604.5,516.5 C 601.404,514.903 598.07,513.736 594.5,513C 544.785,505.415 496.119,509.415 448.5,525C 436.916,529.459 425.916,534.959 415.5,541.5C 398.66,537.967 381.66,535.133 364.5,533C 348.281,531.787 332.281,532.954 316.5,536.5C 299.453,519.752 284.287,501.418 271,481.5C 242.573,429.163 235.239,373.829 249,315.5C 265.646,256.357 301.479,213.19 356.5,186C 358.957,184.488 358.957,183.154 356.5,182C 349.131,181.383 341.798,181.717 334.5,183C 267.533,201.29 220.366,242.456 193,306.5C 167.424,382.358 177.424,453.025 223,518.5C 233.961,532.628 246.128,545.628 259.5,557.5C 258.933,559.03 258.267,560.53 257.5,562C 245.072,569.607 234.072,578.774 224.5,589.5C 155.368,532.865 122.868,459.532 127,369.5C 130.325,286.334 165.492,220.5 232.5,172C 284.106,135.763 341.44,120.763 404.5,127C 494.695,136.821 563.195,180.321 610,257.5C 640.612,314.386 648.612,374.386 634,437.5C 627.999,465.344 618.166,491.678 604.5,516.5 Z"/></g> <g><path style="opacity:1" fill="#fefefd" d="M 316.5,536.5 C 316.063,538.074 315.063,539.241 313.5,540C 296.593,544.123 280.593,550.456 265.5,559C 263.305,559.409 261.305,558.909 259.5,557.5C 246.128,545.628 233.961,532.628 223,518.5C 177.424,453.025 167.424,382.358 193,306.5C 220.366,242.456 267.533,201.29 334.5,183C 341.798,181.717 349.131,181.383 356.5,182C 358.957,183.154 358.957,184.488 356.5,186C 301.479,213.19 265.646,256.357 249,315.5C 235.239,373.829 242.573,429.163 271,481.5C 284.287,501.418 299.453,519.752 316.5,536.5 Z"/></g> <g><path style="opacity:0.989" fill="#40403f" d="M 604.5,516.5 C 561.483,587.723 498.483,629.556 415.5,642C 360.365,649.089 308.032,640.089 258.5,615C 253.906,612.882 249.906,610.048 246.5,606.5C 246.414,605.504 246.748,604.671 247.5,604C 260.545,599.319 273.878,595.652 287.5,593C 314.112,589.907 340.779,587.574 367.5,586C 370.562,584.939 373.062,583.106 375,580.5C 386.112,564.886 399.612,551.886 415.5,541.5C 425.916,534.959 436.916,529.459 448.5,525C 496.119,509.415 544.785,505.415 594.5,513C 598.07,513.736 601.404,514.903 604.5,516.5 Z"/></g> <g><path style="opacity:0.997" fill="#cb7810" d="M 415.5,541.5 C 399.612,551.886 386.112,564.886 375,580.5C 373.062,583.106 370.562,584.939 367.5,586C 340.779,587.574 314.112,589.907 287.5,593C 273.878,595.652 260.545,599.319 247.5,604C 246.748,604.671 246.414,605.504 246.5,606.5C 238.406,601.79 231.072,596.123 224.5,589.5C 234.072,578.774 245.072,569.607 257.5,562C 258.267,560.53 258.933,559.03 259.5,557.5C 261.305,558.909 263.305,559.409 265.5,559C 280.593,550.456 296.593,544.123 313.5,540C 315.063,539.241 316.063,538.074 316.5,536.5C 332.281,532.954 348.281,531.787 364.5,533C 381.66,535.133 398.66,537.967 415.5,541.5 Z"/></g> </svg>';
@@ -161,15 +161,11 @@ exports.getBadgePng = async (req, res) => {
161161
// Generate SVG badge using helper function
162162
const svg = generateBadgeSvgString(place);
163163

164-
// Convert SVG to PNG using resvg
165-
const resvg = new Resvg(svg, {
166-
fitTo: {
167-
mode: 'width',
168-
value: 200 // 2x scale for better quality
169-
}
170-
});
171-
const pngData = resvg.render();
172-
const pngBuffer = pngData.asPng();
164+
// Convert SVG to PNG using sharp
165+
const pngBuffer = await sharp(Buffer.from(svg))
166+
.resize({ width: 200 }) // 2x scale for better quality
167+
.png()
168+
.toBuffer();
173169

174170
// Set cache headers
175171
res.set({

web/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"mysql2": "^3.6.5",
1616
"cors": "^2.8.5",
1717
"dotenv": "^16.3.1",
18-
"@resvg/resvg-js": "^2.6.2"
18+
"sharp": "^0.33.2"
1919
},
2020
"devDependencies": {
2121
"nodemon": "^3.0.2"

0 commit comments

Comments
 (0)