Search code examples
javascriptjquerydata-uri

Is there any method to shorten image data URI using javascript/jquery?


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


Solution

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