PHP image base64 encoding generated dataurl and saved as a picture

Source: Internet
Author: User

<?PHPHeader(' Content-type:text/html;charset=utf-8 '); //read image file, convert to Base64 encoding format        $image _file= ' Aaa.jpg '; $image _info=getimagesize($image _file); //$base 64_image_content = "data:{$image _info[' mime ']};base64,". Chunk_split (Base64_encode (file_get_contents ($ (image_file) ));        $base 64_image_content= "data:{$image _info[' MIME ']}; Base64, ".Base64_encode(file_get_contents($image _file)); //Save the Base64 string as a picture//match the format of the picture        if(Preg_match('/^ (data:\s*image\/(\w+); base64,)/',$base 64_image_content,$result)){          $type=$result[2]; $new _file= "./test. {$type}"; if(file_put_contents($new _file,Base64_decode(Str_replace($result[1], ",$base 64_image_content)))){            Echo' New file saved successfully: ',$new _file; }        }? >$base 64_image_content;? > "/>

PHP image base64 encoding generated dataurl and saved as a picture

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.