title: Encoding an image to a string for inclusion in document
body: <p><strong>Background</strong></p>
  
  <p>At our company the less work there is to manually do the better. Our marketing lady approached me and asked if there is a way to automatically generate a business card with PHP. I told her it should not be an issue if she could save the template as a SVG file.</p>
  
  <p>So she did. Editing the text is pretty easy as I just find the detail spaces and replace it with the user input.</p>
  
  <p><strong>The Problem</strong></p>
  
  <p>The biggest issue that I'm having at the moment is the QR Code that I get from the Google Charts API. The QR Code contains the business card data for easy saving to the phone. The QR Code is retrieved with this call to the Google Charts API:</p>
  
  <pre><code>$request = "http://chart.apis.google.com/chart?chs=500x500&amp;cht=qr&amp;chld=M&amp;chl=" . urlencode($vcard);
  </code></pre>
  
  <p>where <code>$vcard</code> is the VCard that I built with PHP. This works, as the VCard can be used when scanning the QR Code.</p>
  
  <p><strong>What I have tried</strong></p>
  
  <p>Since any image in a SVG file is encoded to text, I tried the following methods:</p>
  
  <pre><code>file_get_contents($request); // Seems the encoding is of as there are weird characters in the result
  img2php.class // Downloaded from PHP Classes, but only converts images in a directory
  </code></pre>
  
  <p><strong>Additional Information</strong></p>
  
  <p>What I have realised is that the QR Code is a PNG that is generated. I don't know if that will affect the answer.</p>
  
  <p>Also, the current QR Code in the business card is encoded as follows:</p>
  
  <pre><code>&lt;image overflow="visible" width="200" height="200"
  xlink:href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEBZwFnAAD/
  7AARRHVja3kAAQAEAAAAHgAA/+4AIUFkb2JlAGTAAAAAAQMA
  EAMCAwYAAAReAAALrQAAHjX/2wCEABALCwsMCxAMDBAXDw0PFxsUEBAUGx8XFxcXFx8eFxoaGhoX
  Hh4jJSclIx4vLzMzLy9AQEBAQEBAQEBAQEBAQEABEQ8PERMRFRISFRQRFBE
      ** random gibberish **
  saaZZmll6QMgIAGkLbb5qxkhmSE47OSXBN9YXg81d+i5LV36LktWPktmRMsMqSFQrXIRg1v8bjuM
  2IBmJtpbymu/Rclq79FyWrv0XJasl5p0mGQqABARbQW4fP8A/s//
  2Q==" transform="matrix(0.2003 0 0 0.2003 56.5049 191.0313)"&gt;
  &lt;/image&gt;
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Is there a way that I can get the QR Code from Google API and then encode it to string and add it to the SVG template?</p>