title: Stack/Merge two svg images in php
body: <p>Is there a way in php to add two svg images into one svg</p>
  <p>Something like it's done with python in <a href="https://github.com/astraw/svg_stack" rel="nofollow noreferrer">https://github.com/astraw/svg_stack</a></p>
  <p>imagecopyresampled can not output to svg.<br />
  Imagemagick convert / montage seem also only for bitmaps</p>
  <hr />
  <p>About the remark &quot;is not really common need for web developers&quot;<br />
  My specific need is to create a downloadable svg composed of a generated QR and a vector logo.<br />
  When you need to show layered svg on a webpage, it could be easier using a javascript/html/css solution.</p>
  <hr />
  <p><strong>SOLUTION</strong><br />
  Altought the question was closed because it was flagged as &quot;We don’t allow questions seeking recommendations for software libraries&quot;<br />
  I am posting my solution, hoping the answer can help some other lost soul ;).</p>
  <p>I found this package <a href="https://github.com/meyfa/php-svg" rel="nofollow noreferrer">https://github.com/meyfa/php-svg</a> and used the following code:</p>
  <pre><code>//load qr code from file
  $fileContent = SVG::fromFile('qr.svg');
  $doc = $fileContent-&gt;getDocument();
  //select logo from svg, scale and move it to the right position 
  $logo = SVG::fromFile('logo.svg')-&gt;getDocument();
  $logo-&gt;getChild(0)-&gt;setAttribute('transform', &quot;translate(73 10) scale(1.29)&quot;);
  $doc-&gt;addChild($logo);
  
  header('Content-Description: File Transfer');
  header(&quot;Content-type: application/octet-stream&quot;);
  header(&quot;Content-disposition: attachment; filename=videoQR.svg&quot;);
  exit($fileContent);
  </code></pre>