Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a way to create manually svg text with php-svg without official method #52

Closed
darkomenx opened this issue Mar 30, 2018 · 3 comments
Labels
question Further information is requested

Comments

@darkomenx
Copy link

This project is very useful !
But no integration for text svg in this library is very annoying.

is there a alternate way to integrate text into SVG generate with this library ? perhaps

  • add string manually into svg tag ?
  • inject external file into svg that represent the text ?
  • include external path code into svg path ?

Thank for your partnership.

@meyfa
Copy link
Owner

meyfa commented Mar 31, 2018

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!

@meyfa meyfa added the question Further information is requested label Mar 31, 2018
@meyfa
Copy link
Owner

meyfa commented Mar 31, 2018

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.

@darkomenx
Copy link
Author

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.

@meyfa meyfa closed this as completed Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants