Skip to content

Instantly share code, notes, and snippets.

@ColonelMoutarde
Last active February 19, 2020 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ColonelMoutarde/f228788d3e2a8e3ac133764789529bc7 to your computer and use it in GitHub Desktop.
Save ColonelMoutarde/f228788d3e2a8e3ac133764789529bc7 to your computer and use it in GitHub Desktop.
<?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