{"id":15650858,"url":"https://github.com/bubkoo/text2svg","last_synced_at":"2025-04-30T07:47:06.462Z","repository":{"id":66336032,"uuid":"55085465","full_name":"bubkoo/text2svg","owner":"bubkoo","description":"🍄  Convert text to svg path.","archived":false,"fork":false,"pushed_at":"2023-09-24T02:28:14.000Z","size":15,"stargazers_count":35,"open_issues_count":4,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-24T07:42:08.172Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bubkoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-30T18:03:59.000Z","updated_at":"2024-10-01T07:53:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"e57bc509-c239-459f-bf29-f8527e44fb75","html_url":"https://github.com/bubkoo/text2svg","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.21052631578947367","last_synced_commit":"b461344ecc4cced52380da9a847f80e4090bc813"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Ftext2svg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Ftext2svg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Ftext2svg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Ftext2svg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bubkoo","download_url":"https://codeload.github.com/bubkoo/text2svg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251665356,"owners_count":21624282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:36:06.065Z","updated_at":"2025-04-30T07:47:06.415Z","avatar_url":"https://github.com/bubkoo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# text2svg\n\n\u003e Convert text to svg path\n\n[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/bubkoo/text2svg/blob/master/LICENSE) \n[![npm:](https://img.shields.io/npm/v/text2svg.svg?style=flat-square)](https://www.npmjs.com/packages/text2svg)\n\n\n## Install\n\n```\n$ npm install --save text2svg \n```\n\n## Usage\n\n```js\nvar Text2svg = require('text2svg');\nvar text2svg = new Text2svg('localFontPath');\nvar svg = text2svg.toSVG('something', options);\n```\n\n## API\n\n### Constructor\n\nThere are three ways to get an instance of `Text2svg`:\n\n- new Text2svg('localFontPath')\n- Text2svg.loadSync('localFontPath')\n- Text2svg.load('fontUrl', callback)\n\nThe `callback` function looks like:\n\n```js\nfunction (text2svg) {\n    // ...\n}\n``` \n\n### toPathData(text, options)\n\nConvert the `text` to path data, which is the attribute value of `d` in the `\u003cpath\u003e` element. Return:\n\n```js\n{\n    width   : width,   // Int, total width\n    height  : height,  // Int, total Height\n    pathData: pathData // Array/String\n}\n```\n\nIf `options.divided` is `true` the pathData will be an Array.\n\n### toPath(text, options)\n\nConvert the `text` to `\u003cpath\u003e` element(s). Return:\n\n```js\n{\n    width   : width,   // Int, total width\n    height  : height,  // Int, total Height\n    pathData: pathData // Array/String\n    path    : path     // Array/String\n}\n```\n\n### toSVG(text, options)\n \nConvert the `text` to `\u003csvg\u003e` element. Return:\n\n```js\n{\n    width   : width,   // Int, total width\n    height  : height,  // Int, total Height\n    pathData: pathData // Array/String\n    path    : path     // Array/String\n    svg     : svg      // String\n}\n```\n\n## Options\n\n### x\n\nHorizontal position of the beginning of the text. (default: 0)\n\n### y\n\nVertical position of the baseline of the text. (default: 0)\n\n### fontSize\n\nSize of the text. (default: 72)\n\n### spacing\n\nThe letter spacing. (default: 0)\n\n### kerning\n\n If `true` takes `kerning` information into account. (default: `true`)\n\n### divided\n\nIf `true` generates individual path for every char. (default: `false`)\n\n### grouped\n\nIf `true` groups the individual `\u003cpath\u003e` with `\u003cg\u003e\u003c/g\u003e` element. (default: `false`)\n\nThis option only works for `toSVG()`.\n\n### title\n\nIf specified will generate a `\u003ctitle\u003e` at the root of `\u003csvg\u003e`. (default: `text`)\n\nThis option only works for `toSVG()`.\n\n### desc\n\nIf specified will generate a `\u003cdesc\u003e` at the root of `\u003csvg\u003e`. (default: `null`)\n\nThis option only works for `toSVG()`.\n\n### Styling the elements\n\nSpecify the padding of the `\u003cpath\u003e` relative to the `\u003csvg\u003e`: \n\n- options.padding\n- options.paddingTop/options['padding-top']\n- options.paddingRight/options['padding-right']\n- options.paddingBottom/options['padding-bottom']\n- options.paddingLeft/options['padding-left']\n\nThe `\u003csvg\u003e`, `\u003cpath\u003e` and `\u003cg\u003e` elements can be styled by any valid attributes. \n\nThe generated `\u003csvg\u003e` has the following default attributes:\n\n```js\n{\n\t'version'    : '1.1',\n    'xmlns'      : 'http://www.w3.org/2000/svg',\n    'xmlns:xlink': 'http://www.w3.org/1999/xlink',\n    'role'   : 'img',\n    'width'  : width,\n    'height' : height,\n    'viewbox': [x, y, width, height].join(' ')\n}\n```\n\nWe can **add**/**update**/**remove** by `options.svg`:\n\n```js\noptions.svg = {\n\t'version': '',     // remove this attribute\n    'role'   : 'logo', // update this attribute\n    'fill'   : 'red'   // add some custiom styles\n}\n```\n\n**Note** that the `width`, `height` and `viewbox` can't be specified.\n\nStyling the `\u003cpath\u003e` by `options.path`. If `divided` is `true` we can style the individual `\u003cpath\u003e` element by `options.path?`, which `?` is the index of each char in the `text`:\n\n```js\n// style for every path(s)\noptions.path  = {\n    'fill': yellow\n};\n\n// style the first char\noptions.path0 = {\n    'fill': '#FF0000',\n    'stroke': '#000000'\n};\n```\n\nAs the same `options.g` specified the style of `\u003cg\u003e` element. \n\n\n \n## Related\n   \n- [logo.svg](https://github.com/bubkoo/logo.svg) Generate a svg logo, then you can embed it in you `README.md`.\n\n\n## Contributing\n\nPull requests and stars are highly welcome.\n\nFor bugs and feature requests, please [create an issue](https://github.com/bubkoo/text2svg/issues/new).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Ftext2svg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbubkoo%2Ftext2svg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Ftext2svg/lists"}