GithubHelp home page GithubHelp logo

Comments (3)

meyfa avatar meyfa commented on August 30, 2024 1

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.

meyfa avatar meyfa commented on August 30, 2024

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.

darkomenx avatar darkomenx commented on August 30, 2024

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.

svg_example

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)

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.