Skip to content

Instantly share code, notes, and snippets.

@akbortoli
Last active February 25, 2019 01:47
Show Gist options
  • Save akbortoli/2003879 to your computer and use it in GitHub Desktop.
Save akbortoli/2003879 to your computer and use it in GitHub Desktop.
PHP: Base64 encode image
<?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