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

Related Articles
How to check Image error or valid in PHP PHP Image Tutorial
How to create Title to Image in PHP PHP Image Tutorial
How to convert a image link to Base64 in PHP PHP Image Tutorial
How to convert all external image link from html string to base64 in PHP PHP Image Tutorial


Read Full:
PHP Image Tutorial
Type:
Develop
Category:
Web Tutorial
Sub Category:
PHP Image Tutorial
Uploaded:
1 month ago
Uploaded by:
Admin
Views:
67
Ref on:
View



Share on: