Skip to content

Instantly share code, notes, and snippets.

@3rdp
Created March 19, 2018 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3rdp/0f8cc56e416c7f0b33931e44d2bc40c7 to your computer and use it in GitHub Desktop.
Save 3rdp/0f8cc56e416c7f0b33931e44d2bc40c7 to your computer and use it in GitHub Desktop.
Scale SVG path; output scaled path to file.
const pathast = require('path-ast')
const fs = require('fs')
const pathStr = 'M0.8572927713394165,-1.4711437225341797C0.8572927713394165,-1.4369948508298824,0.8682440455349504,-1.4005078563677493,0.8709338903427124,-1.366212010383606C0.8776826492648646,-1.2801645194985007,0.8804045332926923,-1.1940720868133363,0.8877229690551758,-1.1080797910690308C0.8915414388864679,-1.0632124180838844,0.8846852909889699,-1.0176606977598863,0.8898215889930725,-0.9727177619934082C0.8963484015589094,-0.9156077349521522,0.8963460263068671,-0.8637286793616796,0.8887723088264465,-0.8069254755973816C0.88760593190895,-0.7981775990253006,0.8941220903616892,-0.7752338143373014,0.8887723088264465,-0.7681007385253906C0.8770788784447072,-0.7525094242138122,0.8493030484211967,-0.7501287302461596,0.8321091532707214,-0.7481637001037598C0.7888428424721896,-0.7432189447632457,0.7389142063430592,-0.7438954126416102,0.6956977844238281,-0.7481637001037598C0.6102252345500444,-0.7566054312046374,0.5268991562099881,-0.7773976475199617,0.445960134267807,-0.8058761954307556C0.38974950469063097,-0.8256540117311927,0.34398735446856843,-0.8670597943835497,0.29380902647972107,-0.8971668481826782C0.24710299637239974,-0.9251905193081364,0.16924553677514168,-0.9580937864210235,0.13850997388362885,-1.0041972398757935C0.11531962248919546,-1.0389828492979085,0.11447718910994563,-1.1389668798633972,0.12277019768953323,-1.1762853860855103C0.1278447248957478,-1.1991207386963256,0.1593423359182355,-1.2252853082946202,0.17103882133960724,-1.2465896606445312C0.2405583071551065,-1.3732146738550672,0.37712505412334785,-1.4097274235791752,0.5099685192108154,-1.431269645690918C0.6215522805802031,-1.4493643421059832,0.735561449594351,-1.4648478031158447,0.8478488922119141,-1.4648478031158447'
let ast = pathast.parse(pathStr)
ast.scale(160, -0.2, -1.5)
// ast.scale(80)
fs.writeFileSync(
'outputPath.txt',
pathast.stringify(ast.toAbsolute())
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment