Merge two images and serve as base64?
<p>Is it possible to merge two images as one AND serve them as a base64? </p>

<p>I am guessing no as there isn't a genuine real image but figured I would ask in case I am misunderstanding something. </p>

<p>For example I have the following - img.php file:</p>

<pre><code>$dest = imagecreatefrompng('myimg.png');
$src = imagecreatefrompng('myimg1.png');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
</code></pre>

<p>Is it possible at all to then </p>

<pre><code>base64_encode(file_get_contents(img.php)))
</code></pre>

<p>Obviously i have attempted and its not working, so I am curious if I am just doing it wrong, or if its just not possible. </p>

<p><strong>UPDATING QUESTION</strong></p>

<p>So apparently it should be working but it doesn't seem to work for me. </p>

<p>Here is the very basic code:</p>

<pre><code>$abs_path = '/home/user/web_dir/path/to/img.php';
$rel_path = '/path/to/img.php';
$data = file_get_contents($abs_path);
echo $data; // should return crazy characters on the screen
echo '&lt;br&gt;&lt;img src="'.$rel_path.'"&gt;'; // should return the image as an image
</code></pre>

<p>The image returns perfectly, the $data returns nothing. Both paths are correct. No errors are returned.</p>

<p>If I run a </p>

<pre><code>$test = base64_encode($data);
echo $test;
</code></pre>

<p>the base64 produced, does not return a valid image. just an empty container. </p>