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?
The key to whether to output pictures directly is
Close header
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