用node和powershell产生觉醒图标的svg symble
This commit is contained in:
parent
a57e5a9c62
commit
294a066510
|
@ -1,6 +1,6 @@
|
|||
/monsters-info/Download-pad.skyozora.com
|
||||
/monsters-info/opencc
|
||||
/monsters-info/node_modules
|
||||
/node_modules
|
||||
*formatting.json
|
||||
/monsters-info/official-API/*-dungeon.json
|
||||
/monsters-info/official-API/*-player-data-*.json
|
||||
|
@ -12,3 +12,4 @@
|
|||
/fonts/.font-spider
|
||||
/images/*.fw.png
|
||||
/monsters-info/package-lock.json
|
||||
/images/project file/awokens
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
@ECHO off
|
||||
title 开始更新 SVG 图标
|
||||
powershell -File "./build symble svgs.ps1"
|
||||
PAUSE
|
|
@ -0,0 +1,54 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const mime = require('mime'); //需要安装
|
||||
const sizeOf = require('image-size'); //需要安装
|
||||
const { DOMImplementation, XMLSerializer } = require('@xmldom/xmldom'); //需要安装
|
||||
|
||||
const directory = './awokens';
|
||||
const files = fs.readdirSync(directory);
|
||||
|
||||
class Icon {
|
||||
constructor(file, dir) {
|
||||
this.fileName = file;
|
||||
this.directory = dir;
|
||||
this.buffer = fs.readFileSync(this.path());
|
||||
this.size = sizeOf(this.buffer);
|
||||
}
|
||||
path() {
|
||||
return path.join(this.directory, this.fileName);
|
||||
}
|
||||
base64() {
|
||||
return `data:${mime.getType(this.fileName)};base64,${this.buffer.toString('base64')}`;
|
||||
}
|
||||
}
|
||||
const iconArr = [];
|
||||
for (const file of files)
|
||||
{
|
||||
const icon = new Icon(file, directory);
|
||||
iconArr.push(icon);
|
||||
}
|
||||
iconArr.sort((a,b)=>{
|
||||
function nameNum(fileName){return parseInt(/^\d+/.exec(fileName)[0])}
|
||||
return nameNum(a.fileName) - nameNum(b.fileName);
|
||||
});
|
||||
|
||||
const svgNS = 'http://www.w3.org/2000/svg';
|
||||
//const dt = new DOMImplementation().createDocumentType('svg:svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
|
||||
//const svg = new DOMImplementation().createDocument(svgNS, 'svg', dt);
|
||||
const svg = new DOMImplementation().createDocument(svgNS, 'svg');
|
||||
|
||||
for (const icon of iconArr)
|
||||
{
|
||||
console.log('正在处理 %s', icon.fileName);
|
||||
const symbol = svg.createElement('symbol');
|
||||
symbol.setAttribute('id', `awoken-${parseInt(path.parse(icon.fileName).name)}`);
|
||||
symbol.setAttribute('viewBox', `0 0 32 32`);
|
||||
svg.documentElement.appendChild(symbol);
|
||||
const image = svg.createElement('image');
|
||||
image.setAttribute('width', icon.size.width);
|
||||
image.setAttribute('height', icon.size.height);
|
||||
image.setAttribute('href', icon.base64());
|
||||
symbol.appendChild(image);
|
||||
}
|
||||
const serialized = new XMLSerializer().serializeToString(svg);
|
||||
fs.writeFileSync('../icon-awoken.svg', serialized);
|
|
@ -0,0 +1,40 @@
|
|||
$xmlSettings = New-Object System.XMl.XmlWriterSettings;
|
||||
$xmlSettings.Indent = $true; # 开启缩进
|
||||
$xmlSettings.IndentChars = ("`t"); # 使用制表符缩进
|
||||
$xmlSettings.OmitXmlDeclaration = $true; # 省略XML声明
|
||||
$xmlWriter = [System.XML.XmlWriter]::Create("..\icon-awoken.svg", $xmlSettings);
|
||||
# Write the XML Decleration and set the XSL
|
||||
$xmlWriter.WriteStartDocument();
|
||||
# Start the Root Element
|
||||
$xmlWriter.WriteStartElement("svg", 'http://www.w3.org/2000/svg'); # 添加根节点
|
||||
|
||||
add-type -AssemblyName System.Drawing; # 要有这一行才能用Image
|
||||
$directory = "awokens";
|
||||
Get-ChildItem $directory | # 读取所有子文件,
|
||||
Sort-Object {[int]$_.basename} | # 按文件名的数字排序
|
||||
ForEach-Object -Process{
|
||||
if($_ -is [System.IO.FileInfo])
|
||||
{
|
||||
Write-Host "正在处理" $_;
|
||||
$content = get-content $_.FullName -encoding byte;
|
||||
$base64 = [convert]::ToBase64String($content);
|
||||
$mime = file --mime-type -b $_.FullName;
|
||||
$id = [int]$_.basename;
|
||||
$image = New-Object System.Drawing.Bitmap $_.FullName;
|
||||
$xmlWriter.WriteStartElement("symbol"); # <-- Start <Object>
|
||||
$xmlWriter.WriteAttributeString("id", "awoken-"+$id);
|
||||
$xmlWriter.WriteAttributeString("viewBox", "0 0 32 32");
|
||||
$xmlWriter.WriteStartElement("image") # <-- Start <SubObject>
|
||||
$xmlWriter.WriteAttributeString("width", $image.Width);
|
||||
$xmlWriter.WriteAttributeString("height", $image.Height);
|
||||
$xmlWriter.WriteAttributeString("href","data:"+$mime+";base64,"+$base64);
|
||||
$xmlWriter.WriteEndElement() # <-- End <SubObject>
|
||||
$xmlWriter.WriteEndElement() # <-- End <Object>
|
||||
}
|
||||
};
|
||||
|
||||
$xmlWriter.WriteEndElement() # 结束根节点
|
||||
# End, Finalize and close the XML Document
|
||||
$xmlWriter.WriteEndDocument()
|
||||
$xmlWriter.Flush()
|
||||
$xmlWriter.Close()
|
|
@ -1,6 +1,6 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const OpenCC = require('opencc-js');
|
||||
const OpenCC = require('opencc-js'); //需要安装
|
||||
const converter = OpenCC.Converter({ from: 'hk', to: 'cn' });
|
||||
const tsConverter = OpenCC.CustomConverter([
|
||||
['点阵图', '像素画'],
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"opencc-js": "^1.0.4"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@xmldom/xmldom": "^0.8.2",
|
||||
"image-size": "^1.0.2",
|
||||
"mime": "^3.0.0",
|
||||
"opencc-js": "^1.0.4"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue