84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
PHP Server Android Client
I need to encode the verification code image generated by the server into base64
Note:does not generate and display images, but directly encodes the generated image resources into base64
so how to do? ? ? ? ? ? ?
闭关修行中......
Main functions:
function base64EncodeImage ($image_file) { $base64_image = ''; $image_info = getimagesize($image_file); $image_data = fread(fopen($image_file, 'r'), filesize($image_file)); $base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data)); return $base64_image; }
demo:
'; echo ''; function base64EncodeImage ($image_file) { $base64_image = ''; $image_info = getimagesize($image_file); $image_data = fread(fopen($image_file, 'r'), filesize($image_file)); $base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data)); return $base64_image; } ?>
Implementation:
================ Supplements =================
GD to base64:
ob_start (); imagejpeg ($img); $image_data = ob_get_contents (); ob_end_clean ();
It is estimated thatob_get_contentsis used to obtain buffer data.Refer to the original text: Original text link
ob_get_contents
PS:Please make good use of Google Baidu.
If the generated verification code is saved on the server side, use file_get_contents to get the image and then base64encode the result and output it.
Main functions:
demo:
Implementation:
================ Supplements =================
GD to base64:
It is estimated that
ob_get_contents
is used to obtain buffer data.Refer to the original text: Original text link
PS:
Please make good use of Google Baidu.
If the generated verification code is saved on the server side, use file_get_contents to get the image and then base64encode the result and output it.