如何从多维数组(或矩阵)生成图像

Is there a way to convert a 3-dimensional array (or matrix) into an RGB image in PHP? Assuming I have a 3D array (width * height * color) of 1000*250*3, how can I convert it into a png image? Maybe the function imagesetpixel() can do the work in a loop. But an efficient way might help to improve response time.

Write the data raw into a binary file, then use ImageMagick to convert it to any file format this supports.

From Supported Image Formats:

Raw: red, green, and blue samples. Use -size and -depth to specify the image width, height, and depth.

which suggests a command line such as

convert your_data_file -colorspace RGB -size 1000x250 efficient_output.png