Skip to content

Instantly share code, notes, and snippets.

@trovster
Created June 11, 2022 20:54
Show Gist options
  • Save trovster/3b00417dfb1bcc6d6c24430667e0e396 to your computer and use it in GitHub Desktop.
Save trovster/3b00417dfb1bcc6d6c24430667e0e396 to your computer and use it in GitHub Desktop.
Using shrhdk/text-to-svg to convert "TM" to SVG paths, using font and multiple colours.
const TextToSVG = require('text-to-svg')
const textToSVG = TextToSVG.loadSync('fonts/Inter.woff')
const colours = Object.values({
blue: '#2490BA',
pink: '#d60058',
purple: '#5f01ad',
green: '#048242',
orange: '#e87204'
}).reverse()
const offset = 15
const colour = colours[Math.floor(Math.random() * colours.length)]
const attributes = { fill: colour }
const options = { fontSize: 450, y: 640, fontWeight: '900', anchor: 'center middle', attributes: attributes }
colours.forEach(function (colour, index) {
const t = textToSVG.getSVG('T', {
...options,
x: 330 + (offset * index),
y: 640 - (offset * index),
attributes: {
...attributes,
fill: colour
}
}).replace(
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="245.25" height="450">',
''
).replace('</svg>', '')
const m = textToSVG.getSVG('M', {
...options,
x: 650 + (offset * index),
y: 640 - (offset * index),
attributes: {
...attributes,
fill: colour
}
}).replace(
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="371.25" height="450">',
''
).replace('</svg>', '')
console.log(t, m)
})
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment