From 2e298601a6f63ec5f46b8e21b9f24c0af5655aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Wed, 20 Apr 2022 20:40:02 +0800 Subject: [PATCH] chore: add .editorconfig --- .editorconfig | 14 +++++++ example/index.js | 2 +- example/write-jpg.js | 2 +- index.js | 93 +------------------------------------------- 4 files changed, 17 insertions(+), 94 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..95b0be8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +insert_final_newline = false diff --git a/example/index.js b/example/index.js index cf5cdc4..7ef02dd 100644 --- a/example/index.js +++ b/example/index.js @@ -15,4 +15,4 @@ svg2img(svgFile, { } }, function (error, buffer) { fs.writeFileSync(__dirname + '/index.png', buffer); -}); \ No newline at end of file +}); diff --git a/example/write-jpg.js b/example/write-jpg.js index feb4d74..c8bed0e 100644 --- a/example/write-jpg.js +++ b/example/write-jpg.js @@ -14,4 +14,4 @@ svg2img(svgFile, { } }, function (error, buffer) { fs.writeFileSync(__dirname + '/write-jpg.jpg', buffer); -}); \ No newline at end of file +}); diff --git a/index.js b/index.js index 627eb89..f1a6eaf 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ function svg2img(svg, options, callback) { // Set the width and height with the options in resvg-js. options.resvg = options.resvg ? options.resvg : {}; - + // JPEG quality (0-100) default: 75 options.quality = options.quality ? parseInt(options.quality, 10) : 75; options.format = options.format ? options.format.toLowerCase() : 'png'; @@ -68,97 +68,6 @@ function svg2img(svg, options, callback) { }); } -// function scale(svgContent, w, h, preserveAspectRatio) { -// var index = svgContent.indexOf('') { -// endIndex = i; -// break; -// } -// } -// svgTag = svgTag.join('').replace(/\n/g, ' ').replace(/\r/g, ''); -// var finalAspectRatio; -// if (preserveAspectRatio) { -// if (typeof preserveAspectRatio === 'string') { -// finalAspectRatio = '"' + preserveAspectRatio + '"'; -// } else { -// if (/ preserveAspectRatio\W/.test(svgContent)) { -// var quoChar = svgTag.match(/ preserveAspectRatio\s*=\s*(['"])/); -// if (quoChar) { -// quoChar = quoChar[1]; -// var aspectRatio = svgTag.match(new RegExp(' preserveAspectRatio\\s*=\\s*' + quoChar + '([^' + quoChar + ']*)')); -// if (aspectRatio && aspectRatio[1]) { -// finalAspectRatio = aspectRatio[1].replace(/^\s*(\S.*\S)\s*$/, '"$1"'); -// } -// } -// } -// } -// } -// var props = {}; -// var splits = svgTag.substring(4, svgTag.length - 1).split(' '); -// var lastKey; -// var i; -// for (i = 0; i < splits.length; i++) { -// if (splits[i] === '') { -// continue; -// } else { -// if (splits[i].indexOf('=') < 0) { -// props[lastKey] = props[lastKey] + ' ' + splits[i]; -// } else { -// var keyvalue = splits[i].split('='); -// lastKey = keyvalue[0]; -// props[lastKey] = keyvalue[1]; -// } -// } -// } -// var ow = props['width'] ? parseInt(props['width'].replace('"', ''), 10) : null, -// oh = props['height'] ? parseInt(props['height'].replace('"', ''), 10) : null; -// if (w) { -// props['width'] = '"' + w + '"'; -// } -// if (h) { -// props['height'] = '"' + h + '"'; -// } -// if (!props['viewBox']) { -// props['viewBox'] = '"' + [0, 0, ow ? ow : w, oh ? oh : h].join(' ') + '"'; -// } -// props['preserveAspectRatio'] = finalAspectRatio || '"none"'; - -// // update width and height in style attribute -// if (props['style'] && props['style'].length > 2) { -// var styleUpdated = false; -// var styleStr = props['style'].substring(1, props['style'].length - 1); -// var styles = styleStr.split(';'); -// for (var i = 0; i < styles.length; i++) { -// var styleKV = styles[i].split(':'); -// if (styleKV.length === 2) { -// var key = styleKV[0].trim(); -// if (key === 'width') { -// styles[i] = 'width : ' + w + 'px'; -// styleUpdated = true; -// } else if (key === 'height') { -// styles[i] = 'height : ' + h + 'px'; -// styleUpdated = true; -// } -// } -// } -// if (styleUpdated) { -// props['style'] = '"' + styles.join(';') + '"'; -// } -// } - -// var newSvgTag = [''); -// return svgContent.substring(0, index) + newSvgTag.join(' ') + svgContent.substring(endIndex + 1); -// } - function loadSVGContent(svg, callback) { if (svg.indexOf('data:image/svg+xml;base64,') >= 0 && !/^