Comments (3)
I'm not quite sure what you're asking about exactly, so I'll try to outline different ways.
Setting arbitrary attributes:
$node->setAttribute(name, value)
Setting text content:
$node->setValue(string)
Example:
$image = SVGImage::fromString('<svg><title></title></svg>');
$title = $image->getDocument()->getChild(0);
$title->setValue('hello world');
echo $image;
Modifies the title tag to be <title>hello world</title>
. This works for any node, not just titles.
Custom node types:
Implement your own class inheriting from SVG\Nodes\SVGNode
(or SVG\Nodes\SVGNodeContainer
if you need it to contain other nodes). This is simple, see for example SVGTitle.php or SVGText.php. Then you can add instances of those classes to your document and they will be included in the generated SVG markup.
Path data:
Since you've mentioned path data, let me just say that you can use $path->setDescription(value)
for that.
Example:
$image = new SVGImage('100%', '100%');
$doc = $image->getDocument();
$doc->addChild(
(new SVGPath())
->setDescription('M 100,100 L 200,200 h -100 Z')
);
Did any of this answer your question?
If not, please try to state your question more clearly, perhaps by giving an example of what you're trying to do. Thanks!
from php-svg.
Some of the features mentioned were added quite recently and did not make it into any release yet. Therefore, I pushed a new release (v0.8.0) just now.
from php-svg.
Hi Meyfa,
I need to include dynamic text into my svg "picture". Text from database or other PHP class which is include in my svg and transform the format for display position, color or others.
All of "hello" label in this picture is controlled by your svg library (position, color, text label, .....)
Ok for settings text content and attribute. It not directly response of my issue but I think that could be interesting. Perhaps use JS obliquely for format this as I like.
Custom nodes is very interesting but I need lot of work for create dynamic svg depends on a dynamic variables PHP.
Perhaps create lot of link between SVGPath and string php with const like that :
$SVGPathTitrePicture = 'M 100,100 L 200,200 h -100 Z';
$SVGPathLabel1Picture = 'M 105,200 L 250,285 h -100 Z';
$SVGPathLabel2Picture = 'M 123,156 L 200,210 h -100 Z';
What do you think ?
Thank you for your new release.
from php-svg.
Related Issues (20)
- Fonts are not working on SVG HOT 1
- External fonts not working for text object HOT 1
- PHP 8.1 Deprecated notices HOT 7
- [feature request] generate sprite from an array of svg HOT 2
- I am facing an issue, to centralize the icon, text, and tagline in the SVG viewBox.
- Running PHPUnit tests on PHP 8 HOT 3
- Dropping support for PHP versions < 7.3 HOT 8
- SVGImage cannot be rasterised to PNG or JPG HOT 5
- SVGStyleParser::parseCss cannot handle duplicate selectors
- Error if font-size not set explicitly
- Issue while rendering `rect` without `x` or `y` attributes
- Does not use internal CSS
- Support SVG `<pattern>`
- SVGTextPath node not being rasterized when added as child of SVGText HOT 4
- Drop unmaintained PHP, publish a release HOT 14
- Buggy rasterization image
- Security options HOT 5
- Migrate to PHP-CS-Fixer
- Deprecated: Implicit conversion from float to int loses precision
- Rendering 'italic' or 'oblique' text misses fonts with 'Oblique' subfamily HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-svg.