Php converts an array (, 0.) to an image output-php Tutorial

Source: Internet
Author: User
In php, convert an array (, 0.) to an image output and obtain the binary array of an image from a third-party interface. The result is similar to the following:
$ Img_data = array ,...);

How can I convert the above array to image output?


Reply to discussion (solution)

This data is abnormal.

If this is the number of image data

Echo join ('', array_map ('chr', $ img_data ));

If this is the number of image data

Echo join ('', array_map ('chr', $ img_data ));


#2. positive solution. the score will be closed later;
However, I have not been familiar with PHP for a long time. I am not very familiar with its principles. can I give a rough explanation of @ xuzuning?

The above data is equivalent:
255 11 22 .....
After I directly set the header output, an image is displayed.

Array_map enables each element of the array to execute the specified function.
Array_map ('chr', $ img_data) means to execute the chr function for every value of $ img_data and convert the value to a character.
The join function concatenates arrays into strings.

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.