Can you please guide me how can I convert an image from a URL to base64 encoding?
Very simple and to be commonly used:
function getDataURI($imagePath) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->file($imagePath);
return 'data:'.$type.';base64,'.base64_encode(file_get_contents($imagePath));
}
//Use the above function like below:
echo '
';
echo '
';
Note: The Mime-Type of the file will be added automatically (taking help from this PHP documentation).