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.