How to display Base64 images in HTML?

后端 未结 11 2298
一整个雨季
一整个雨季 2020-11-21 06:10

I\'m having trouble displaying a Base64 image inline.

Can someone point me in the right direction?



  
         


        
11条回答
  •  盖世英雄少女心
    2020-11-21 07:05

    If you have PHP on the back-end, you can use this code:

    $image = 'http://images.itracki.com/2011/06/favicon.png';
    // Read image path, convert to base64 encoding
    $imageData = base64_encode(file_get_contents($image));
    
    // Format the image SRC:  data:{mime};base64,{data};
    $src = 'data: '.mime_content_type($image).';base64,'.$imageData;
    
    // Echo out a sample image
    echo '';
    

提交回复
热议问题