<?php
$path = 'images/thumb1.gif';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo substr($base64, 0, 50);
?>
Output
data:image/gif;base64,R0lGODlhWABgAPcAAPL36nF1TOav