Using Base64 to encode and decode images

Source: Internet
Author: User
Trying to transfer images through JSON, this is the time to think of using Base64 encoding method to image. The main steps are

1, the image file encoding, converted to Base64 encoded format, and a long string of characters;

2, the character can be transmitted through JSON;

3, the destination party receives the JSON array, takes out the encoded string, and decodes, displays the picture

The difficulty of this method is mainly in the processing of the image codec, the following is the implementation of PHP encoding and decoding processing code

 
  ?>

which

Preg_match ()

function : performs a regular expression match

return value: pattern The number of matches returned. Its value will be 0 times (mismatched) or 1 times, because Preg_match () will stop the search after the first match. If an error occurs , Preg_match () returns FALSE .

file_put_contents ()

Function: writes a string to a file

Return value: The function successfully returns the number of bytes written to the data in the file, and returns when failed FALSE。





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the use of Base64 to encode and decode the image, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.