Horje
How to convert a image link to Base64 in PHP

I think that it should be.


FUll Code

See the Example.
index.php
Example: PHP
<?php
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 '<img src="' . getDataURI('https://horje.com/avatar.png') . '" alt="">';
echo '<img src="' . getDataURI('https://horje.com/avatar.png') . '" alt="">';
?>

Output should be:

Demo

Output should be:





link base64

Type :
Develop
Category :
Web Tutorial
Sub Category :
PHP Image Tutorial
Uploaded by :
Admin


Read Article
https://horje.com/learn/1434/reference