Last active
February 25, 2019 01:47
-
-
Save akbortoli/2003879 to your computer and use it in GitHub Desktop.
PHP: Base64 encode image
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 $path | |
* @param string $type | |
*/ | |
function base64_encode_image ($path, $type) | |
{ | |
$binary = fread(fopen($path, 'rb'), filesize($path)); | |
return 'data:image/' . $type . ';base64,' . base64_encode($binary); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment