Code Monkey home page Code Monkey logo

vectro's Introduction

Vectro

A library designed to aid in the dynamic creation of SVG images in PHP.

Basic Usage

Each SVG element is represented by its own class. First, you will need an outermost <svg> element, which is done like so:

$svg = new Vectro\SvgElement(100, 100); // A 100x100 pixel SVG image

Then, you can define whatever elements you need to. For a <circle>, for example:

$circle = new Vectro\CircleElement(50, 50, 25); // A circle with its center at co-ordinates 50,50 and a radius of 25

In Vectro, element attributes are set via object properties, so if you wanted to apply fill to the <circle>:

$circle->fill = 'red';

If you need to set an attribute with a hyphen in it, replace the hyphen with an underscore in the property name:

$circle->stroke = 'black';
$circle->stroke_width = '3';

If you would prefer to use the style attribute for element styling rather than individual attributes, Vectro provides a couple of methods to facilitate this:

$circle->addStyle('fill', 'red');
$circle->addStyles(array('stroke' => 'black', 'stroke-width' => '3px'));

Then the <circle> needs to be made a child of the outermost <svg>:

$svg->add($circle);

When you've finished constructing your SVG, you use it to create an instance of Vectro\Document and use the output() method to output the SVG string:

$document = new Vectro\Document($svg);
// Then optionally serve the string as SVG
header('content-type: image/svg+xml');
echo $document->output();

Requirements

  • PHP 5.3+
  • libxml extension

License

Vectro is released under the MIT license

vectro's People

Contributors

ockle avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.