• Base64 Encoding for Images

    Base64 is an encoding format that represent binary data. here requesting images are in string format to reduce server load time. In this post I will show you how to make images to strings with PHP.

    1
    2
    3
    4
    5
    6
    
    <!--?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.'" ?-->';
    ?&gt;

Comments on this post

Leave a Reply

  • Security Code :


    × 5 = thirty