Comments (2)
Yes, that's most definitely possible.
<svg>
nodes can contain other <svg>
nodes. As such, you can simply load image A, load image B, and then add B as a child node of A.
For example:
<?php
use SVG\SVG;
$a = SVG::fromFile(__DIR__.'/a.svg');
$b = SVG::fromFile(__DIR__.'/b.svg');
$a->getDocument()->addChild($b->getDocument());
echo $a;
File 'a.svg':
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="5" height="20" />
</svg>
File 'b.svg':
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="40" cy="20" r="8" />
<circle cx="80" cy="20" r="8" />
</svg>
Script output (formatted):
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="5" height="20" />
<svg viewBox="0 0 100 100">
<circle cx="40" cy="20" r="8" />
<circle cx="80" cy="20" r="8" />
</svg>
</svg>
from php-svg.
Note that if you need the output without the <?xml version="1.0" encoding="utf-8"?>
line (for embedding in an HTML document), you can pass false
to SVG::toXMLString()
like so:
<?php
use SVG\SVG;
$a = SVG::fromFile(__DIR__.'/a.svg');
$b = SVG::fromFile(__DIR__.'/b.svg');
$a->getDocument()->addChild($b->getDocument());
echo $a->toXMLString(false);
Moreover, if you need to place image B somewhere deeper inside image A (inside a <g>
element, for example), you can do that, too. You would just need to navigate to the target node and call addChild()
on that. For example:
<?php
use SVG\SVG;
$a = SVG::fromFile(__DIR__.'/a.svg');
$b = SVG::fromFile(__DIR__.'/b.svg');
$groups = $a->getDocument()->getElementsByTagName("g");
$g = $groups[0];
$g->addChild($b->getDocument());
echo $a->toXMLString(false);
I hope I could answer your question (albeit a bit late). If not, feel free to reopen this issue.
from php-svg.
Related Issues (20)
- Improve resiliency against whitespace in styles
- 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
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.