How to parse Base64 data to generate pictures in PHP _php tips

Source: Internet
Author: User
Tags base64

The example in this article describes how PHP parses base64 data to generate pictures. Share to everyone for your reference, specific as follows:

$base = "/9j/4aaqskzjrgabaqeakacqaad/ 4qcmrxhpzgaatu0akgaaaagabqesaamaaaabaaeaaaeaaauaaaabaaaasgebaauaaaabaaaaugeoaamaaaabaaiaaidpaaqaaaabaaaawgaaaaaaaacqaaaaa qaaajaaaaabaaogaqadaaaaaqabaacgagaeaaaaaqaaahkgawaeaaaaaqaaahiaaaaa/ 9saqwaffrcbfxmfgxkbiyefjs9omi8rky9freg4tnbjdnruy21rfiyyl3yeqyzrbzvtnam4vsjkyhiv2+rzwumyxmja/ 9saqwehiymvks9bmjjbwibtgmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmda/ 8aaeqgacgbyaweiaairaqmraf/eab8aaaefaqebaqebaaaaaaaaaaabagmebqyhcakkc// Ealuqaaibawmcbamfbqqeaaabfqecawaeequsitfbbhnryqcicrqygzghccncscevuthwjdnicoijchyxgbkajsynkckqndu2nzg5okneruzhselku1rvvldy Wvpjzgvmz2hpann0dxz3ehl6g4sfhoeiiyqsk5svlpeymzqio6slpqeoqaqys7s1tre4ubrcw8tfxsfiycrs09tv1tfy2drh4upk5ebn6onq8flz9px29 /j5+v/eab8baambaqebaqebaqeaaaaaaaabagmebqyhcakkc// Ealuraaibagqeawqhbqqeaaecdwabagmrbauhmqysqvehyxetijkbcbrckagxwqkjm1lwfwjy0qowjdthjfexgbkajicokso1njc4otpdrevgr0hjslnuvvzx Wflay2rlzmdoawpzdhv2d3h5eokdhiwgh4ijipktljwwl5izmqkjpkwmp6ipqrkztlw2t7i5usldxmxgx8jjytlt1nxw19jz2ulj5oxm5+jp6vlz9px29/j5+v/aaawdaqaceqmrad8a6giiigaooqf5scl+ daepihu4phmqepquswosc0uwjvph939app8a9n9ahooasczt1ykecg6hnvkasdkhfafyioem7n+dtagjipalrrrqauuuuafffqzv/ cpxoabljuob0/nudffmaoopyixph50anoqtes9swptr+ 6b1wgcoinpgu56j1ptabto5ch9vsm0uawwqrkdkwq8l4o09dvikauuuuaix2qt6vujycmp5zhqpwokybrrrqadalkoxqi/juaffx606b/ wggblfffaektz+ruhpjdaxhpqn31+tom/1hoazrrrqavajbcgpeqts255i/ggceiiikbbcfea9qiqs4++ ppudmaooooaklceyozeo6ioqkjrh82do96ai6kmzoierk+1n3xr91mn3oai12je3qdkjjyst3pxcueasgaooooakfd/rbtkfd/ rbqbzooopaq3a6goasyruqiq1maoopvg5gpwgb6kfxe34cmo5c5nompzbr0fmoakkkkacpnoepkjkdrudoiba49+ Kag0u6rdrku2gaqsafot6co6sqlhm+taelfffiaqtkm1vy1zprqhxboaq06mhxbpskzspwasmarhle+ ppkkkaciiigaooooafkwzsj0plfabjwotadkxe2ktdkzgmxffvt6qbrrrqauuuuanda4waruhq89pwrvfafoip2hu9okyyxhtbpgr0u7y/ 8adnjsb+6fyoasinifz2xuiwafeoaaivuscavyjjcd1prtgabgdflsakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkap/
2q== ";
$img = Base64_decode ($base 64);
$a = file_put_contents ('./test.jpg ', $img);//Save picture, return byte number//print_r ($a); Header ("Content-type:imagE/jpeg ");//Direct output display JPG format image echo $img; 

The Operation effect chart is as follows:

PS: Here again for you to recommend several online picture Tools for everyone to use the reference

Picture converted to BASE64 encoded online tool:
Http://tools.jb51.net/transcoding/img2base64

Online picture format conversion (jpg/bmp/gif/png) Tool:
Http://tools.jb51.net/aideddesign/picext

ico icon Online generation tool:
http://tools.jb51.net/aideddesign/ico_img

For more information on PHP related content readers can view the site topics: "PHP graphics and pictures Operating skills summary", "Basic PHP Grammar Introductory Course", "PHP Operations and Operator Usage Summary", "PHP object-oriented Program Design Introductory Course", "PHP Network Programming Skills Summary", "PHP array (Array) Operations tips Encyclopedia, "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP Common database Operation tips Summary"

I hope this article will help you with the PHP program design.

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.