Created
September 8, 2017 16:59
-
-
Save mikecastrodemaria/80dcb98e421b4ee1c4f0f55262576035 to your computer and use it in GitHub Desktop.
WP : transform images to base64 images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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