0

I have this "little" problem...

In my web app, I receive an xml message from the server that I parse with jquery. In the xml there is an element <Image> with these attributes: key and value. The value attribute is a string that represents the image file (.png) compressed with the gzip algorithm (using the System.IO.Compression class in C#). Is there a way to decompress the value in javascript and then get the corresponding decompressed string?

1
  • Sorry, are you receiving an image content or path through a webservice? Jan 29, 2013 at 16:47

4 Answers 4

3

This looks like it's a combination of already answered questions. You need to ungzip the string and then convert from string to image. When dealing with problems like this it's best to break it down into the smallest chunks you can. That way your searches will yield more applicable results if you can't find your exact issue.

JavaScript implementation of Gzip

Javascript Hex String to Image

1
  • Exactly as I thought people should break this down. Get the GZip out of the way and convert to image. Using DATA URI might have browser compatibility issue but not in near future. Jan 29, 2013 at 16:51
1

just simple example

<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />

where iVBORw0KGgoAAAANSUhEUgAAADIA... - is your value..

0

I asume the image is base64 encoded. In that case you need to set the src property of the image with the image data prefixed with data:image/png;base64,

Embedding Base64 Images

3
  • Just Firefox support this method. Jan 29, 2013 at 16:50
  • Is this due to the gzip encoding, as I believe this worked in the latest version of Chrome. I would need to double check. Jan 29, 2013 at 16:52
  • gzip compression does work and most common browsers (listed on w3c) are able to encode and decode to gzip so should not be an issue. Jan 29, 2013 at 16:53
0

The server send to me the string of the image in a gzip compress format. I try the tag but the browser seems not to decompress the image string. The image is converted in base64 format. Now I try again. Is there a way to check if the string is compress ed in the right way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.