admin管理员组

文章数量:1401291

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

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

Share Improve this question edited May 28, 2015 at 5:36 Antony Varghese asked May 28, 2015 at 5:29 Antony VargheseAntony Varghese 451 silver badge5 bronze badges 4
  • What problems are you running into that makes the URI too long? – Austin Brunkhorst Commented May 28, 2015 at 5:31
  • I need to send the image data URI as an attachment via GET/POST method but I got an error message that the string length is too long – Antony Varghese Commented May 28, 2015 at 5:35
  • 1 Why can't you just send the binary data? – BoltClock Commented May 28, 2015 at 5:36
  • 800k characters is about 780 kilobytes of data, or 0.76 megabytes, which shouldn't be a problem at all with a POST request. – adeneo Commented May 28, 2015 at 5:37
Add a ment  | 

2 Answers 2

Reset to default 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.

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 pressed.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.

本文标签: Is there any method to shorten image data URI using javascriptjqueryStack Overflow