简体   繁体   中英

Create Image From 2D RGB Array

In my previous question , I managed to get a 2-dimensional array (in JavaScript) of rgb values from a canvas' imagedata. Now that I have it, is there a way to use PHP to reconstruct the canvas image from the 2D RGB array? Specifically, how do I get the 2D JS array into PHP (JSON I believe, but I don't know how) and then how do I use it to remake the image? :-)

Edit:

I forgot to mention that the browser lacks toDataURL() , which is why I'm trying this method.

It would be easier to convert the canvas imagedata to a data URL using the canvas.toDataURL() method. You will get a string that you can easily transfer using a standard POST request.

PHP then has base64_decode() to convert the data URL back into an image stream.

您应该按照@ devnull69的说法进行操作,但如果您绝对必须使用PHP在服务器端构建映像,请使用imagecreatetruecolorimagecolorallocateimagesetpixel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM