Base64 Encoding for Images in PHP

December 30, 2012 7605 views 0 comments

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.

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

$img_src = “image/sample.png”;
$imgbinary = fread(fopen($img_src, “r”),
$img_str = base64_encode($imgbinary);
echo ‘<img src=”data:image/jpg;base64,’.
$img_str.’” />’;


Leave a Reply