dev-master
9999999-dev http://kartsims.github.com/easysvg/PHP library to generate SVG XML
MIT
The Requires
- php >=5.3.0
by Simon Tarchichi
Wallogit.com
2017 © Pedro Peláez
PHP library to generate SVG XML
Generate SVG images from SVG font easily., (*1)
The SVG data produced here is directly extracted from the font .svg file. This does not use the <text> tag., (*2)
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 = "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., (*3)
Sets the font attributes. This is a shortcut for :, (*4)
$this->setFontSVG($path); $this->setFontSize($size); $this->setFontColor($color);
These 3 methods are explicit enough, I won't go through these in here., (*5)
Use SVG font kerning pairs. Default is false., (*6)
Adds a CSS-like line-height value. A numeric value (float) where 1 is the line height defined by the font itself., (*7)
Adds a CSS-like letter-spacing value. A numeric value (float) expressed in em where 1 is the width of the m character., (*8)
Add text to the SVG (will be converted to simple path), (*9)
$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 attributesReturn XML string of the whole SVG., (*10)
Add an attribute to the main SVG., (*11)
You may need these to play around with SVG definitions., (*12)
Applies a translate transformation to a definition. This basically applies matrix calculation to a definition., (*13)
Applies a translate transformation to definition. This basically applies matrix calculation to a definition., (*14)
Applies a scale transformation to definition. This basically applies matrix calculation to a definition., (*15)
Returns a SVG-formatted definition of a string. This method is used by addText method., (*16)
$text : String UTF-8 encodedReturns the width and height of a string. This method is also used to set the width/height of the SVG (if none specified)., (*17)
$text : String UTF-8 encodedReturns a SVG-formatted definition of an unicode character., (*18)
$code : Unicode definition (in hex format)Returns the width of a character., (*19)
$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, (*20)
$def : SVG definition$attributes (optional) : list of tag attributesResets the SVG data. Used to start a new SVG without creating a new instance., (*21)
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., (*22)
MIT. Please feel free to pull, fork, and so on., (*23)
PHP library to generate SVG XML
MIT