Skip to content
Advertisement

html2canvas save image doesn’t work

I’m rendering a screenshot with html2canvas 0.4.0 and want to save it as image on my webserver.

To do so, I’ve written the following function:

JavaScript

JavaScript

saveJPG.php

JavaScript

After the canvas is rendered I can perfectly append it to the HTML body, but saving it on my server result in a corrupted (?) file.

I can read the dimensions in IrvanView, but the image is transparent / empty? The file is about 2.076 KB large. So it’s not really empty.

I tried this with JPEG as well and it results in a corrupted file and IrfanView says something like “bogus marker length”.

The screenshot has the dimensions of 650×9633. Is it to much data for a POST-Method?

Advertisement

Answer

In case someone stumbles over the same problem, here is how I solved it:

The problem depended on the fact, that + in URLs is interpreted as an encoded space (like %20) by most servers. So I needed to encode the data first and then send it via POST to my designated PHP function.

Here is my code:

JavaScript

JavaScript

savePNG.php

JavaScript

Cheers!

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement