Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikecastrodemaria/80dcb98e421b4ee1c4f0f55262576035 to your computer and use it in GitHub Desktop.
Save mikecastrodemaria/80dcb98e421b4ee1c4f0f55262576035 to your computer and use it in GitHub Desktop.
WP : transform images to base64 images
/*
charge img_src value buy your own image
needs to be used with a caching system
*/
$img_src = "img/sample.jpg";
$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
$img_str = base64_encode($imgbinary);
echo '<img src="data:image/jpeg;base64,'.$img_str.'" alt="Alt text" />';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment