- Saved searches
- Use saved searches to filter your results more quickly
- kartsims/easysvg
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- shrhdk/text-to-svg
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Generate SVG definitions and XML using PHP
kartsims/easysvg
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Generate SVG images from SVG font easily.
The SVG data produced here is directly extracted from the font .svg file. This does not use the tag.
require 'easySVG.php'; $svg = new EasySVG(); $svg->setFont("om_telolet_om-webfont.svg", 100, '#000000'); $svg->addText("Simple text display"); $svg->addAttribute("width", "800px"); $svg->addAttribute("height", "120px"); echo $svg->asXML();
require 'easySVG.php'; $text pl-s">Simple text display\netc."; $svg = new EasySVG(); $svg->setFontSVG("om_telolet_om-webfont.svg"); $svg->setFontSize(100); $svg->setFontColor('#000000'); $svg->setLineHeight(1.2); $svg->setLetterSpacing(.1); $svg->setUseKerning(true); $svg->addText($text); // set width/height according to text list($textWidth, $textHeight) = $svg->textDimensions($text); $svg->addAttribute("width", $textWidth."px"); $svg->addAttribute("height", $textHeight."px"); echo $svg->asXML();
This will output inline SVG for you to play with. You can echo it, save it to a file or whatever.
setFont($path, $size, $color = null)
Sets the font attributes. This is a shortcut for :
$this->setFontSVG($path); $this->setFontSize($size); $this->setFontColor($color);
These 3 methods are explicit enough, I won’t go through these in here.
Use SVG font kerning pairs. Default is false .
Adds a CSS-like line-height value. A numeric value (float) where 1 is the line height defined by the font itself.
Adds a CSS-like letter-spacing value. A numeric value (float) expressed in em where 1 is the width of the m character.
addText($text, $x, $y, $attributes=array())
Add text to the SVG (will be converted to simple path)
- $text : String UTF-8 encoded
- $x : X position of the text (starting from left), can be center to center the text horizontally
- $y : Y position of the text (starting from top), can be center to center the text vertically
- $attributes (optional) : list of tag attributes
Return XML string of the whole SVG.
Add an attribute to the main SVG.
SVG data manipulation methods
You may need these to play around with SVG definitions.
Applies a translate transformation to a definition. This basically applies matrix calculation to a definition.
Applies a translate transformation to definition. This basically applies matrix calculation to a definition.
Applies a scale transformation to definition. This basically applies matrix calculation to a definition.
Returns a SVG-formatted definition of a string. This method is used by addText method.
Returns the width and height of a string. This method is also used to set the width/height of the SVG (if none specified).
Returns a SVG-formatted definition of an unicode character.
Returns the width of a character.
- $char : Character
- $is_unicode : Boolean that tells if the character is a unicode string or a UTF-8 character.
Add a path to the SVG data
Resets the SVG data. Used to start a new SVG without creating a new instance.
Apply a matrix to a definition. Used to apply any kind of transformations, you shouldn’t need this, but it is available so you may play with it.
MIT. Please feel free to pull, fork, and so on.
About
Generate SVG definitions and XML using PHP
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Convert text to SVG path without native dependence.
License
shrhdk/text-to-svg
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Convert text to SVG path without native dependence.
const TextToSVG = require('text-to-svg'); const textToSVG = TextToSVG.loadSync(); const attributes = fill: 'red', stroke: 'black'>; const options = x: 0, y: 0, fontSize: 72, anchor: 'top', attributes: attributes>; const svg = textToSVG.getSVG('hello', options); console.log(svg);
svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 180 72"> svg>
$ npm install --save text-to-svg
An example for loading default font synchronously. The default font is IPA font. This method only works on Node.js.
const textToSVG = TextToSVG.loadSync(); const svg = textToSVG.getSVG('hello'); console.log(svg);
An example for loading font synchronously. This method only works on Node.js.
// Argument is file path (NOT URL) const textToSVG = TextToSVG.loadSync('/fonts/Noto-Sans.otf'); const svg = textToSVG.getSVG('hello'); console.log(svg);
An example for loading font asynchronously.
// First argument is URL on web browsers, but it is file path on Node.js. TextToSVG.load('/fonts/Noto-Sans.otf', function(err, textToSVG) const svg = textToSVG.getSVG('hello'); console.log(svg); >);
Get the path data for d attribute of path .
Options is an optional object containing:
- x : Horizontal position of the beginning of the text. (default: 0 )
- y : Vertical position of the baseline of the text. (default: 0 )
- fontSize : Size of the text (default: 72 ).
- kerning : if true takes kerning information into account (default: true )
- letterSpacing : letter-spacing value in em .
- tracking : tracking value. (em / 1000)
- anchor : Anchor of object in coordinate. (default: ‘left baseline’ )
- ( left , center , right ) + ( baseline , top , middle , bottom )
M5.27-54.07L10.62-54.07L10.62-34.00Q15.86-39.23 21.02-39.23Q26.89-39.23 29.60-34.07Q31.11-31.15 31.11-27L31.11-3.66L25.77-3.66L25.77-25.42Q25.77-34.14 20.18-34.14Q16.42-34.14 13.57-31.39Q10.62-28.44 10.62-24.64L10.62-3.66L5.27-3.66L5.27-54.07ZM67.68-14.27Q64.55-2.25 54.07-2.25Q47.57-2.25 43.77-7.66Q40.32-12.62 40.32-20.74Q40.32-28.51 43.56-33.47Q47.36-39.23 54-39.23Q66.97-39.23 67.82-19.65L45.74-19.65Q46.16-7.07 54.14-7.07Q60.47-7.07 62.05-14.27L67.68-14.27M62.05-24.26Q60.89-34.42 54-34.42Q47.36-34.42 45.95-24.26L62.05-24.26ZM92.81-11.53Q92.81-8.44 95.77-8.44Q98.19-8.44 101.07-9L101.07-3.62Q96.82-3.02 94.82-3.02Q87.19-3.02 87.19-10.51L87.19-54.07L92.81-54.07L92.81-11.53ZM128.81-11.53Q128.81-8.44 131.77-8.44Q134.19-8.44 137.07-9L137.07-3.62Q132.82-3.02 130.82-3.02Q123.19-3.02 123.19-10.51L123.19-54.07L128.81-54.07L128.81-11.53ZM162.07-39.23Q168.68-39.23 172.44-33.40Q175.68-28.55 175.68-20.74Q175.68-14.87 173.74-10.44Q170.16-2.21 161.93-2.21Q155.57-2.21 151.77-7.63Q148.32-12.59 148.32-20.74Q148.32-29.53 152.30-34.56Q156.09-39.23 162.07-39.23M161.93-34.21Q158.06-34.21 155.88-30.16Q153.95-26.61 153.95-20.74Q153.95-15.33 155.53-11.92Q157.71-7.24 162-7.24Q165.94-7.24 168.12-11.29Q170.05-14.84 170.05-20.67Q170.05-26.75 168.05-30.23Q165.90-34.21 161.93-34.21Z
Get the path element of SVG.
Options is an optional object containing:
- x : Horizontal position of the beginning of the text. (default: 0 )
- y : Vertical position of the baseline of the text. (default: 0 )
- fontSize : Size of the text (default: 72 ).
- kerning : if true takes kerning information into account (default: true )
- letterSpacing : letter-spacing value in em .
- tracking : tracking value. (em / 1000)
- anchor : Anchor of object in coordinate. (default: ‘left baseline’ )
- ( left , center , right ) + ( baseline , top , middle , bottom )
Options is an optional object containing:
- x : Horizontal position of the beginning of the text. (default: 0 )
- y : Vertical position of the baseline of the text. (default: 0 )
- fontSize : Size of the text (default: 72 ).
- kerning : if true takes kerning information into account (default: true )
- letterSpacing : letter-spacing value in em .
- tracking : tracking value. (em / 1000)
- anchor : Anchor of object in coordinate. (default: ‘left baseline’ )
- ( left , center , right ) + ( baseline , top , middle , bottom )
Options is an optional object containing:
- x : Horizontal position of the beginning of the text. (default: 0 )
- y : Vertical position of the baseline of the text. (default: 0 )
- fontSize : Size of the text (default: 72 ).
- kerning : if true takes kerning information into account (default: true )
- letterSpacing : letter-spacing value in em .
- tracking : tracking value. (em / 1000)
- anchor : Anchor of object in coordinate. (default: ‘left baseline’ )
An example of return value.
< "x": 0, "y": -63.3515625, "baseline": 0, "width": 180, "height": 72, "ascender": 63.3515625, "descender": -8.6484375 >
text-to-svg depends on the following softwares. I thank great authors a lot.
These are released under the MIT license
About
Convert text to SVG path without native dependence.