This is the code I use to generate the base64 image. it works perfectly on local host but, however it generates a different output on a remote host.
<?php
//Your Image
$imgSrc = "http://pngimg.com/upload/water_PNG3290.png";
//getting the image dimensions
list($width, $height) = getimagesize($imgSrc);
$dif = $width - $height;
//saving the image into memory (for manipulation with GD Library)
$myImage = imagecreatefrompng($imgSrc);
imageAlphaBlending($myImage, true);
// calculating the part of the image to use for thumbnail
if ($width > $height) {
$y = $width/13; //width
$x =$width/2.8 ; //height
$smallestSide = ($width - $height) /(0.002 * $dif );
} else {
$x = 0;
$y = ($height - $width);
$smallestSide = $width;
}
// copying the part into thumbnail
$thumbSize = 381;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagefill($thumb,0,0,0x7fff0000);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
imagealphablending( $thumb, false );
imagesavealpha( $thumb, true );
//final output
ob_start ();
imagepng ($thumb);
$image_data = ob_get_contents ();
ob_end_clean ();
$image_data_base64 = base64_encode ($image_data);
echo "<img src='data:image;base64,".$image_data_base64."'/>";
?>