2

I have converted a canvas image to data URI using jquery and the data URI is too long, say about 800,000 characters.

Is there any methods for reducing/shortening the length of the data URI?

I need to send the image data via GET/POST method but I got an error message that the string length is too long

2 Answers2

6

canvas.toDataURL() support different image types. You could try the different formats or use jpg and decrease the quality:

e.g. for 100% quality:

canvas.toDataURL("image/jpeg", 1.0)

or for 50%:

canvas.toDataURL("image/jpeg", 0.5)

This should reduce the image size and therefore the amount of image data.

Nitek
  • 2,515
  • 2
  • 23
  • 39
  • You won't be able to reduce the amount of data by a resonable amount. As already suggested in the other comments: If you use POST for transmission, it shouldn't be a problem – Nitek May 28 '15 at 06:00
0

You cant.As this is the canvasimagedata(which is a base64 string).If you reduce it,some of the data maybe lost.Base64 itself is fairly compressed.You can check out JavaScript implementation of Gzip

You can try adjusting the image quality i.e (image/jpeg,value from 0-1) But this wont reduce it to a great extent.

Community
  • 1
  • 1
AkshayJ
  • 771
  • 6
  • 15