0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I forgot to mention that the browser this is intended for lacks toDataURL() :-(
0

You should do it as @devnull69 says, but if you absolutely must build the image on the serverside with PHP, use imagecreatetruecolor, imagecolorallocate and imagesetpixel.

3 Comments

The browser this is needed for unfortunately lacks toDataURL(). :-( How would I use those functions to reconstruct the 2d array? Sorry, I've never done anything like this before.
I'd like to be able to get the base64 data of the created image as well. Curse the browser's lack of toDataURL()...
Check the linked php docs pages linked for some example code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.