Skip to content

Instantly share code, notes, and snippets.

@mcabreradev
Forked from jasny/image-embed-html.php
Created September 27, 2016 16:08
Show Gist options
  • Save mcabreradev/4cc9563d339af77848e5fc81f6785b1a to your computer and use it in GitHub Desktop.
Save mcabreradev/4cc9563d339af77848e5fc81f6785b1a to your computer and use it in GitHub Desktop.
Create base64 encoded image to embed in HTML
<?php
$files = array_slice($argv, 1);
foreach ($files as $file) {
$picture = file_get_contents($file);
$size = getimagesize($file);
// base64 encode the binary data, then break it into chunks according to RFC 2045 semantics
$base64 = chunk_split(base64_encode($picture));
echo '<img src="data:' . $size['mime'] . ';base64,' . "\n" . $base64 . '" ' . $size[3] . ' />', "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment