A package to convert an svg graphic file into a Php object. based on Blade UIkit
by using the svg()
function we can retrieve an svg file using the file name and convert it into an object of the Svg class and manipulate it as such.
$mySvg = svg('my_svg');
dd($mySvg);
svg file my_svg.svg
ASK\Svg\Svg ({)#427 ▼
#name: "svg"
#elements: array:1 [▼
0 => ASK\Svg\Configurators\G ({)#301 ▼
#name: "g"
#elements: array:37 [▶]
#context: ASK\Svg\Svg ({)#427(})
#transforms: ASK\Svg\Transformation ({)#424 ▼
#transformations: array:1 [▼
0 => array:1 [▼
"matrix" => NumPHP\Core\NumArray ({)#423 ▶(})
]
]
(})
#isTransformable: true
-attributes: array:1 [▶]
+"g": array:37 [▶]
(})
]
#context: null
#isTransformable: false
-attributes: array:6 [▼
"id" => "my_svg"
"width" => "473"
"height" => "477"
"viewBox" => "0 0 473 477"
"fill" => "none"
"xmlns" => "http://www.w3.org/2000/svg"
]
+style: ASK\Svg\Configurators\Style ({)#426 ▼
#name: "style"
#context: ASK\Svg\Svg ({)#427(})
#isTransformable: false
-attributes: []
-classes: []
-rules: []
(})
+"g": array:1 [▼
0 => ASK\Svg\Configurators\G ({)#301 ▶(})
]
(})
Full name: \ASK\Svg\Svg
the Svg document
Class Svg implements: \ASK\Svg\Conteiner
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
public |
style | Configurators\Style |
Class methods
Svg (string fileName, string contents, array attributes = []): mixed
Parameter | Type | Description |
---|---|---|
fileName | string |
|
contents | string |
|
attributes | array |
returns
get the Style element from the string content
public getStylefromContent(): string
returns
remove the string Style from the string content
public removeStylefromContent(): self
returns
get the Style element
public style(): Configurators\Style
returns
set the Style element
public setStyle(Configurators\Style style): self
Parameter | Type | Description |
---|---|---|
style | Configurators\Style |
returns
replace the Classes names in the string content
public replaceClasses(Configurators\Style style, string content): string
Parameter | Type | Description |
---|---|---|
style | Configurators\Style |
|
content | string |
returns
merge one or more Svgs in this svg
public mergeSvgs(Svg[] param): Svg
Parameter | Type | Description |
---|---|---|
param | Svg[] |
returns
implements of Htmlable, toHtml return a string form of the svg in HTML format
public toHtml(): string
returns
get all the Svg elements in this svg, this array conteins all the elements in order
public getAllSvgElements(mixed svg): array
Parameter | Type | Description |
---|---|---|
svg | mixed |
returns
cleanContent remove all string contents in the complet object
public cleanContent(): self
returns
Get the value of content (Conteiner implement) //TODO implementation of container
public getContent(): mixed
returns
Set the value of content (Conteiner implement) //TODO implementation of container
public setContent(mixed content): self
Parameter | Type | Description |
---|---|---|
content | mixed |
returns
removes those attributes that belong exclusively to the svg element
public removeSvgAttribute(): void
returns
get those attributes that belong exclusively to the svg element
public getOnlySvgAttribute(): array
returns
Full name: \ASK\Svg\SvgElement
This object represents all the elements within an svg document
from the svg parent element to the internal elements or figures such as <path>, <circle> or <g>, passing through configuration elements such as <style>, <defs> among others
all elements are accessible in order through the attribute $elements, as well as through the array in the property with the name of the element
for example:
- $svg->g returns all <g> elements
- $svg->elements[0] return the first element in the <svg></svg>
- $svg->g[0]->elements[0] return the first element in the <g></g>
Class SvgElement implements: \Illuminate\Contracts\Support\Htmlable
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
name | string |
|
protected |
elements | SvgElement[] |
|
protected |
contents | string |
|
protected |
context | SvgElement |
|
protected |
transforms | Transformation |
|
protected |
isTransformable | bool |
Class methods
SvgElement (string name, string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
name | string |
|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
Make this element Transformable
public makeTransformable(): void
returns
make this element Untransformable
public makeUntransformable(): void
returns
get or set the name of the element
public name(string arg = ''): string|self
Parameter | Type | Description |
---|---|---|
arg | string |
returns
get or set the id attribute of the element in the attributes property
public id(string arg = ''): string|self
Parameter | Type | Description |
---|---|---|
arg | string |
returns
set or get the Transformation Object for the element
public transform(mixed arg = null): Transformation|string
Parameter | Type | Description |
---|---|---|
arg | mixed |
returns
get the string contents of the elements
- this method is similar at toHtml but get just the string of the content without the tag string
public contents(): string
returns
remove the string Contents property from the object
public removeContents(): self
returns
set the string Contents property in the object
public setContents(string contents): self
Parameter | Type | Description |
---|---|---|
contents | string |
returns
get the property Context that is the parent SVG element of this element
public getContext(): SvgElement|null
returns
get all Elements from the string content this method make all found elements as SvgElement Objects and put in a property with the element name
public getAllElements(): void
returns
set a neu Element in this object
public setElement(string name, mixed element): void
Parameter | Type | Description |
---|---|---|
name | string |
|
element | mixed |
returns
merge the attributes conteined in a string tag with the array attributes
public mergeAttributes(string tag, array attributes): array
Parameter | Type | Description |
---|---|---|
tag | string |
|
attributes | array |
returns
remove coments from the string content
public removeComents(): self
returns
implements of Htmlable, toHtml return a string form of the svg element in HTML format
public toHtml(): string
returns
remove the property Id
public removeId(): self
returns
toArray
public toArray(): void
returns
public serialize(mixed data): mixed
Parameter | Type | Description |
---|---|---|
data | mixed |
returns
public unserialize(mixed data): mixed
Parameter | Type | Description |
---|---|---|
data | mixed |
returns
find the first group element with the name $element and return the new corresponding SvgElement instance or null if not found
public findFirstGroupElement(string element): SvgElement|null
Parameter | Type | Description |
---|---|---|
element | string |
returns
return the first Element in the elements array or null if not found
public findFirstElement(string elementName): SvgElement|null
Parameter | Type | Description |
---|---|---|
elementName | string |
returns
find the first non-group element with the name $element and return the new corresponding SvgElement instance or null if not found
public findFirstNonGroupElement(string element): SvgElement|null
Parameter | Type | Description |
---|---|---|
element | string |
returns
get the attributes of a element froma string tag ()
public getElementAttributes(string tag): array
Parameter | Type | Description |
---|---|---|
tag | string |
returns
get the Transformations of the element and make the corresponding Transformation Object
public getTransformations(): void
returns
find an element by its id and return it or null if not found
public getElementById(string id): SvgElement|null
Parameter | Type | Description |
---|---|---|
id | string |
returns
get the start position point of an Shape element by its Id and return it or null if not found
public getStartPointById(string id): \NumPHP\Core\NumArray|null
Parameter | Type | Description |
---|---|---|
id | string |
returns
return true if the element has content or false otherwise
public hasContext(): void
returns
Full name: \ASK\Svg\Shapes\Shape
An element that make a Shape in a svg document
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
startPosition | \NumPHP\Core\NumArray |
Class methods
Shape (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
get the Start position o the element
public getStartPosition(): void
returns
renderAttributes return a string with attributes in a HTML format (overloaded Method from RenderAttributes)
protected renderAttributes(): string
returns
(overloaded Method from SvgElement)
public toHtml(): string
returns
Full name: \ASK\Svg\Shapes\Circle
A Circle element in a svg document
Class Circle inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
cx | float |
|
protected |
cy | float |
|
protected |
r | float |
Class methods
Circle (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
get the center of the circle
public center(): \NumPHP\Core\NumArray
returns
get the Diameter of the circle
public diameter(): float
returns
get the Radio of the circle
public radio(): float
returns
get the Area of the circle
public area(): float
returns
Full name: \ASK\Svg\Shapes\Ellipse
A Ellipse element in a svg document
Class Ellipse inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
cx | float |
|
protected |
cy | float |
|
protected |
rx | float |
|
protected |
ry | float |
Class methods
Ellipse (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
get the Center of the ellipse
public center(): \NumPHP\Core\NumArray
returns
get the x Radio of the ellipse
public radioX(): float
returns
get the y Radio of the ellipse
public radioY(): float
returns
get the Area of the ellipse
public area(): float
returns
Full name: \ASK\Svg\Shapes\Line
A Line element in a svg document
Class Line inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
x1 | float |
|
protected |
y1 | float |
|
protected |
x2 | float |
|
protected |
y2 | float |
Class methods
Line (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
get teh Logitud of the line
public long(): float
returns
Full name: \ASK\Svg\Shapes\Path
A Path element in a svg document
Class Path inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
private |
dString | string |
|
protected |
d | array |
Class methods
Path (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
(overloaded Method from SvgElement)
public toHtml(): string
returns
content get the content string of the svg elemnt to print in a HTML document
public content(): string
returns
getExistingComands get the existing comands in a d attribute from a string
public getExistingComands(string d): array
Parameter | Type | Description |
---|---|---|
d | string |
returns
renderAttributes return a string with attributes in a HTML format (overloaded Method from RenderAttributes)
protected renderAttributes(): string
returns
Full name: \ASK\Svg\Shapes\Polygon
A Polygon element in a svg document
Class Polygon inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
points | array |
Class methods
Polygon (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
(overloaded Method from SvgElement)
public toHtml(): string
returns
get the array Points from a string
public getPoints(string points): array
Parameter | Type | Description |
---|---|---|
points | string |
returns
Full name: \ASK\Svg\Shapes\Polyline
A Polyline element in a svg document
Class Polyline inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
points | array |
Class methods
Polyline (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
(overloaded Method from SvgElement)
public toHtml(): string
returns
get the array Points from a string
public getPoints(string points): array
Parameter | Type | Description |
---|---|---|
points | string |
returns
Full name: \ASK\Svg\Shapes\Rect
A Rect element in a svg document
Class Rect inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
x | float |
|
protected |
y | float |
|
protected |
width | float |
|
protected |
height | float |
|
protected |
rx | float |
|
protected |
ry | float |
Class methods
Rect (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
get the Center of the rectangle
public center(): \NumPHP\Core\NumArray
returns
get the Area of the rectangle
public area(): float
returns
Full name: \ASK\Svg\Shapes\Text
a Text element in a svg document
Class Text inherits from class: Shape
Class Properties
visibility | Property | Type | Description |
---|
Class methods
Text (string contents, array attributes = [], SvgElement context = null): mixed
Parameter | Type | Description |
---|---|---|
contents | string |
|
attributes | array |
|
context | SvgElement |
returns
Full name: \ASK\Svg\DCommands\Command
A command in a d attribute of a svg path
There are five line commands for <path> nodes.
- M - Move
- L - Line
- H - Horizontal
- V - Vertical
- Z - Close
und five arc commands.
- C - Cubic Curve
- Q - Quadratic Curve
- S - Short Cubic Curve
- T - Together Multiple Quadratic Curve
- A - Arc
Each command contains a $coordinates array with all the parameters of each point, as well as a reference to the previous command.
Class Command implements: \Illuminate\Contracts\Support\Htmlable
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
nextPoint | int |
|
protected |
count | mixed |
|
protected |
type | string |
|
protected |
coordinates | array |
|
protected |
prev | DCommands\Command |
|
protected |
position | int |
|
protected |
endPointCoordinates | array |
Class methods
Command (string type, array parameters = [], ?DCommands\Command prev = null): mixed
Parameter | Type | Description |
---|---|---|
type | string |
|
parameters | array |
|
prev | ?DCommands\Command |
returns
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
getComand
return the name of the command. Uppercase if it's absolute lowercase if relative
public getComand(): string
returns
setEndPoint set the values of the coordinates of the end point in the command list, both Absolute and Relative
public setEndPoint(array relativePoint, array absolutePoint): void
Parameter | Type | Description |
---|---|---|
relativePoint | array |
|
absolutePoint | array |
returns
public toHtml(): mixed
returns
getEndPoint returns an array with the x and y value of the end point. If the parameter "absolute" is put to true the Absolute value of the end point is returned, relative is returned otherwise
public getEndPoint(bool absolute = true): array
Parameter | Type | Description |
---|---|---|
absolute | bool |
returns
resetNext
public resetNext(): void
returns
getLastMComand returns the last M command in the "d" attribute
public getLastMComand(): DCommands\Command|null
returns
getPoint returns the array with the x and y parameters of the n point, if the parameter "absolute" is set to true, the Absolute values are returned, relative are retuned otherwise
public getPoint(int n = null, bool absolute = false): array
Parameter | Type | Description |
---|---|---|
n | int |
|
absolute | bool |
returns
getDinstance get the distance between tow points, if the second parameter is not gived, returns the Absolut distans of the point
public getDinstance(array fromPoint, array toPoint = []): array
Parameter | Type | Description |
---|---|---|
fromPoint | array |
|
toPoint | array |
returns
Full name: \ASK\Svg\DCommands\A
A comand "a" in a d attribute of a svg path
Arcs are sections of circles or ellipses. For a given x-radius and y-radius, there are two ellipses that can connect any two points (last end point and (x, y)). Along either of those circles, there are two possible paths that can be taken to connect the points (large way or short way) so in any situation, there are four possible arcs available.
Because of that, arcs require seven parameters: A rx ry x-axis-rotation large-arc-flag sweep-flag x y
a rx ry x-axis-rotation large-arc-flag sweep-flag dx dy
A command hat in aditional to the other commands a getCenter Methode
Class A inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
getCenter get the centero of the n arc
public getCenter(int n = null): array
Parameter | Type | Description |
---|---|---|
n | int |
the arc number of which we want the center |
returns
Full name: \ASK\Svg\DCommands\C
A comand "c" in a d attribute of a svg path
The cubic curve, C, is the slightly more complex curve. Cubic Béziers take in two control points for each point. Therefore, to create a cubic Bézier, three sets of coordinates need to be specified.
C x1 y1, x2 y2, x y c dx1 dy1, dx2 dy2, dx dy
Class C inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
Full name: \ASK\Svg\DCommands\H
A comand "h" in a d attribute of a svg path
A command draws a horizontal line, this command only take one parameter since they only move in one direction.
H x h dx
Class H inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
x | float |
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
getX
public getX(): float
returns
setX Set the value of x
public setX(float x): self
Parameter | Type | Description |
---|---|---|
x | float |
returns
Full name: \ASK\Svg\DCommands\L
A comand "h" in a d attribute of a svg path
L x y l dx dy
Class L inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
Full name: \ASK\Svg\DCommands\M
A comand "m" in a d attribute of a svg path
M x y m dx dy
Class M inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
private |
x | float |
|
private |
y | float |
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
getMDinstance get the distance between last m point and the point of parameter
public getMDinstance(array toPoint = []): array
Parameter | Type | Description |
---|---|---|
toPoint | array |
returns
Get the value of x
public getX(): float
returns
Set the value of x
public setX(float x): self
Parameter | Type | Description |
---|---|---|
x | float |
returns
Get the value of y
public getY(): float
returns
Set the value of y
public setY(float y): self
Parameter | Type | Description |
---|---|---|
y | float |
returns
Full name: \ASK\Svg\DCommands\Q
A comand "q" in a d attribute of a svg path
Q x1 y1, x y q dx1 dy1, dx dy
Class Q inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
Full name: \ASK\Svg\DCommands\S
A comand "s" in a d attribute of a svg path
S x2 y2, x y s dx2 dy2, dx dy
Class S inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
Full name: \ASK\Svg\DCommands\T
A comand "t" in a d attribute of a svg path
T x y t dx dy
Class T inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
Full name: \ASK\Svg\DCommands\V
A comand "v" in a d attribute of a svg path
V y v dy
Class V inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|---|---|---|
protected |
y | float |
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
getY
public getY(): float
returns
setY
public setY(float y): self
Parameter | Type | Description |
---|---|---|
y | float |
returns
Full name: \ASK\Svg\DCommands\Z
A comand "z" in a d attribute of a svg path
Class Z inherits from class: Command
Class Properties
visibility | Property | Type | Description |
---|
Class methods
initialization is a configuration method for the specific type of command
public initialization(mixed parameters): void
Parameter | Type | Description |
---|---|---|
parameters | mixed |
returns
getPoint returns the array with the x and y parameters of the n point, if the parameter "absolute" is set to true, the Absolute values are returned, relative are retuned otherwise
public getPoint(mixed n = null, mixed absolute = true): array
Parameter | Type | Description |
---|---|---|
n | mixed |
|
absolute | mixed |
returns
- Svg - the Svg document.
- SvgElement - # An element belonging to a svg structure.
- Shape - An element that make a Shape in a svg document.
- Circle - A Circle element in a svg document.
- Ellipse - A Ellipse element in a svg document.
- Line - A Line element in a svg document.
- Path - A Path element in a svg document.
- Polygon - A Polygon element in a svg document.
- Polyline - A Polyline element in a svg document.
- Rect - A Rect element in a svg document.
- Text - a Text element in a svg document.
- Command - A command in a d attribute of a svg path.
- A - A comand "a" in a d attribute of a svg path.
- C - A comand "c" in a d attribute of a svg path.
- H - A comand "h" in a d attribute of a svg path.
- L - A comand "h" in a d attribute of a svg path.
- M - A comand "m" in a d attribute of a svg path.
- Q - A comand "q" in a d attribute of a svg path.
- S - A comand "s" in a d attribute of a svg path.
- T - A comand "t" in a d attribute of a svg path.
- V - A comand "v" in a d attribute of a svg path.
- Z - A comand "z" in a d attribute of a svg path.
This file is public domain. Use it for any purpose, including commercial applications. Attribution would be nice, but is not required. There is no warranty of any kind, including its correctness, usefulness, or safety.
Author: Alberto Solorzano Kraemer ( alberto.kraemer@gmail.com, @betobetok )
This document was automatically generated from source code comments on 2022-03-25 using phpDocumentor and cvuorinen/phpdoc-markdown-public