PHP convert MongoDB\BSON\Binary to base64
<p>I have jpeg files stored (in binary format) in a MongoDB and I would like to retrieve them in PHP and have them encoded in Base64 (so that I can provide the image as inline in HTML (<code>&lt;img src="data:jpeg;base64," . base64_encode($imgData-&gt;getData()) . " /&gt;</code>).</p>

<p>Unfortunately the <code>base64_encode($imgData-&gt;getData())</code> generates the following exception: </p>

<blockquote>
  <p>Catchable fatal error: Object of class MongoDB\BSON\Binary could not
  be converted to string in (...)</p>
</blockquote>

<p>What would be the best approach to get the binary data encoded in base64?</p>

<p>Many thanks,
Tom</p>