Andrew on Nostr: Had a simple icon SVG the other day that was in a 32px canvas and we needed it in a ...
Had a simple icon SVG the other day that was in a 32px canvas and we needed it in a 20px canvas, so rather than piss about with Inkscape or whatever, I pasted the path data into Node and wrote this deeply cursed one-liner:
x.replaceAll(/[\d.]+/g, a => (parseFloat(a)*(20/32)).toFixed(2).replace(/\.?0+$/,''))
AND IT WORKED FIRST TIME
there is no way that should have worked, but it did, the icon is now exactly the right size and the file is smaller to boot
Published at
2024-09-20 11:22:58Event JSON
{
"id": "cffcff39f049daee3a7d542d88fb8d69e0ffafd9b0fc5a476c8d25b10114a5ae",
"pubkey": "00dbdbbfbe02172d1e4426f29292f24e8a78e29ba9187097bc26d254ba1f7bbd",
"created_at": 1726831378,
"kind": 1,
"tags": [
[
"proxy",
"https://mathstodon.xyz/users/andrewt/statuses/113169621195067919",
"activitypub"
]
],
"content": "Had a simple icon SVG the other day that was in a 32px canvas and we needed it in a 20px canvas, so rather than piss about with Inkscape or whatever, I pasted the path data into Node and wrote this deeply cursed one-liner:\n\nx.replaceAll(/[\\d.]+/g, a =\u003e (parseFloat(a)*(20/32)).toFixed(2).replace(/\\.?0+$/,''))\n\nAND IT WORKED FIRST TIME\n\nthere is no way that should have worked, but it did, the icon is now exactly the right size and the file is smaller to boot",
"sig": "b696bc9e432b4c752b1eb171c532a698c19b9b4f5cceeb91c563c2df8073eab4b695091ee2897234a846ecef076ab65cbb8bb1338cbbbda4de2c4cde124017e1"
}