php - How to output image in base64
伊谢尔伦
伊谢尔伦 2017-05-24 11:32:19
0
1
797

That’s it. Today I wrote a PHP template for generating verification codes based on the information on the Internet:

But I don’t want him to output the image directly, but output the image in base64. How should I do it? I have tried many methods without success, unless it is necessary:

$img_file = 'https://www.xxxxxxxxxx.com/authcode.php'; $img_info = getimagesize($img_file); $img_src = "data:{$img_info['mime']};base64," . base64_encode(file_get_contents($img_file)); echo "";

How can I directly output base64 in getCode?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all (1)
淡淡烟草味

The key to whether to output pictures directly is

  1. Close header

  2. imagepng function, the second parameter sets the image saving location.

Then read the storage location to read the image and convert it to base64.

php documentation

The comments section below the document may have the answers you need

ob_start(); imagepng($image); $image_data = ob_get_contents(); ob_end_clean();

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!