** EDIT ** I have to export a big canvas (5Mo < my_export < 40Mo) and POST it with ajax. I have to POST it using the fewer Content-Length bytes.
When I export my canvas (with toDataUrl), it always return me a base64 representation of a .png file with an alpha channel. Alpha channel weight is about 25% of image's data and I don't need it.
Suggested answer :
- PNG compression is good. If the alpha channel is flat (all the same value) then it will not take up much space. Even with fully opaque alpha channel, the (compressed) .png file is larger. (about +10% on a few tests).
- You should fill the canvas (using the color you want for the background) before drawing on it. I already founded this solution on stackoverflow but it seems it doesnt works
- Base64 encode add 34% more bytes. Already solved. Using this solution : convert-data-uri-to-file-then-append-to-formdata (A Uint8Array into a Blob into a FormData)
Is there a way to export my canvas as .png but without alpha channel ? If "no", is there a way (lib) in javascript to trim alpha channel ? Export as .jpeg is not a solution, I need a .png file.
Thanks ! : )