Skip to content

Commit

Permalink
Use resvg for dimensions calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed May 1, 2022
1 parent bc32e4c commit 78f1484
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 49 deletions.
11 changes: 2 additions & 9 deletions lib/svg-sprite/utils/calculate-svg-dimensions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { Resvg } = require('@resvg/resvg-js');
const imageSize = require('image-size');

/**
* @typedef {object} Dimension
Expand All @@ -17,20 +16,14 @@ const imageSize = require('image-size');
*/
function calculateSvgDimensions(svg) {
try {
const resvg = new Resvg(svg, {
const { width, height } = new Resvg(svg, {
logLevel: 'error',
font: {
loadSystemFonts: false // It will be faster to disable loading system fonts.
}
});
const pngData = resvg.render();

const dimensions = imageSize.imageSize(pngData);

return {
height: dimensions.height,
width: dimensions.width
};
return { width, height };
} catch (error) {
const e = new Error(error);
e.name = 'DimensionsCalculationError';
Expand Down
39 changes: 0 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"csso": "^4.2.0",
"cssom": "^0.5.0",
"glob": "^7.2.0",
"image-size": "^1.0.1",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"mustache": "^4.2.0",
Expand Down

0 comments on commit 78f1484

Please sign in to comment.