0

I was reading about Canvas toDataUrl increases file size of image, as I used this method myself in my code. But it's really a big trouble for me if the size of image is getting bigger when it's represented in text.

So I wanted to ask you my dear friends : is there any alternative that will work better? Why the image is represented exactly in base64? Is there any other "bases" we can convert it to?

I need to keep lots of images using minimum of the memory...

Is there any javascript approach (serverside library or any other method) to represent images in text form using possibly small amount of memory?

Community
  • 1
  • 1
vach
  • 10,571
  • 12
  • 68
  • 106
  • Just use the binary representation... What's your application? – Rob W Sep 05 '12 at 21:48
  • we are not your colleagues ... what backend language are you using? you dont have to save the image in the format toDataUrl uses. – hackattack Sep 05 '12 at 21:49
  • I'ts for now a simple web app (php used serverside)... I use php now. I need to represent image in text format using possibly less memory... – vach Sep 05 '12 at 21:50
  • Rob how can i get binary representation of the image? (i have document loaded, image objects are all loaded... how can i get text representation using javascript?) – vach Sep 05 '12 at 21:52
  • 1
    To represent a binary (8bit = values from 0 to 255) image "stream" as text which is supposed to be "character encoding free" you can use only 6 bit of a byte (values from 0 to 63). So every chunk of 3 image bytes (3*8 bit = 24 bit) will have to be represented by 4 text bytes (4*6 bit = 24 bit). So the resulting file will always grow to about four thirds of the original file size – devnull69 Sep 05 '12 at 21:56

1 Answers1

2

There are a couple of possibilities:

  • Convert the base64 string to a binary string (just decode the string ;) )
  • Zip the string
  • Store it in a UInt8Array
  • Draw the image to a canvas (don't know about the memory footprint of canvas elements though..)

You can combine some of the options above.

Van Coding
  • 24,244
  • 24
  • 88
  • 132