8

I can bring images from the web using the Import command like this:

Import["http://blog.wolfram.com/wp-content/uploads/2008/06/se-30.jpg"]

good image

Sometimes the web request is more complicated so I must to use URLFetch. For that, this is what I have tried to do:

ImportString[
    URLFetch["http://blog.wolfram.com/wp-content/uploads/2008/06/se-30.jpg"],
"JPG"]

unreadable image

Do you know how to make the image load correctly? I suspect that this is related to strings encodings, but I have not been able to solve it.

Luciano
  • 253
  • 2
  • 9
Gustavo Delfino
  • 8,348
  • 1
  • 28
  • 58

1 Answers1

11

This is a bug due to the fact that URLFetch is dealing incorrectly with line breaks. Here's a workaround:

in1 = URLFetch[
  "http://blog.wolfram.com/wp-content/uploads/2008/06/se-30.jpg", 
  "ContentData"
];
ImportString[FromCharacterCode[in1]]

You can compare this technique to the other as follows:

in2 = ToCharacterCode[URLFetch[
  "http://blog.wolfram.com/wp-content/uploads/2008/06/se-30.jpg"]
];
SequenceAlignment[in1, in2]
Mark McClure
  • 32,469
  • 3
  • 103
  • 161