Monday, 11 April 2016

Base64 encoding for images

Base64 is an encoding format that represent binary data. Google new feature instant previews are in text format, here Google requesting images(screen shots) are in string format to reduce server load time. In this post I will show you how to make images to strings with PHP.
base64 for images



PHP images to strings
PHP terminology there is a function called base64_encode().
<?php

$img_src = "image/sample.png";
$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
$img_str = base64_encode($imgbinary);
echo '<img src="data:image/jpg;base64,'.$img_str.'" />';

?>

You can also try it live at https://www.base64decode.org/

0 comments :

Post a Comment