Skip to content

Instantly share code, notes, and snippets.

@hengkiardo
Created November 6, 2012 10:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hengkiardo/4023855 to your computer and use it in GitHub Desktop.
Save hengkiardo/4023855 to your computer and use it in GitHub Desktop.
Create image data URIs (base64) using PHP
// A few settings
$image = 'cricci.jpg';
// Read image path, convert to base64 encoding
$imageData = base64_encode(file_get_contents($image));
// Format the image SRC: data:{mime};base64,{data};
$src = 'data: '.mime_content_type($image).';base64,'.$imageData;
// Echo out a sample image
echo '<img src="',$src,'">';
@scansio
Copy link

scansio commented Dec 16, 2022

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment