Last active
February 19, 2020 14:27
-
-
Save ColonelMoutarde/f228788d3e2a8e3ac133764789529bc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param string $pathToImg | |
* @return string | |
*/ | |
function toBase64(string $pathToFile): string | |
{ | |
$type = pathinfo($pathToFile, PATHINFO_EXTENSION); | |
$data = file_get_contents($pathToFile); | |
return 'data:image/' . $type . ';base64,' . base64_encode($data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment