biggs06 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, I'm trying to download book covers from www.netlibrary.com, my problem is that most of the images I download are unreadable garbage, however, certain ones get through just fine. Heres some example code:
#!/usr/bin/perl use strict; use LWP::UserAgent; my $ROBOT = LWP::UserAgent->new(); my $response = $ROBOT->get("http://a1835.g.akamai.net/f/1835/276/3h/ww +w.netlibrary.com/covers/158/800/158800.gif"); open(FILE, ">test.gif"); binmode FILE; binmode stdout; print FILE $response->content(); close FILE;
I'm running Fedora so the binmodes should have no effect, correct? I've also tried
#!/usr/bin/perl use strict; use LWP::Simple qw/getstore/; getstore("http://a1835.g.akamai.net/f/1835/276/3h/www.netlibrary.com/c +overs/158/800/158800.gif", "test2.gif");
with the same results. Some images such as this one get downloaded just fine. Any idea what's going on here?

Replies are listed 'Best First'.
Re: Downloading Corrupted Images
by sgifford (Prior) on May 10, 2007 at 16:21 UTC
    Your program works for me, but there's definitely something odd with that image. I can open it fine in Firefox, either with the URL or with the file downloaded by your program. But my regular image viewer (Eye of Gnome) crashes when I try to open the file, whether it's the one downloaded from Perl or saved from the Web browser. The file saved from the Web browser is identical to the file retrieved by your program.

    However, if I convert the image with Image::Magick into an image with the same specs (I'm just running convert test.gif test2.gif), it will open up fine in my image viewer.

    So, maybe your problem isn't with the Perl script, but with a weird image screwing up later steps in the process, and maybe Image::Magick can make the image less weird.

      OK, I moved over to a windows machine and it looks like it can read all the images. I guess I will just have to finish my work on it. Thanks for the helping me narrow it down, it was giving me a headache. I guess the problem was that they are just bad gifs?
        Well, weird anyways. Some image viewers seem to open them, others don't, so it could be a problem with the image viewer or with the GIF. It's fair to say that they're "GIFs that tend to confuse image viewers", though. :-)
Re: Downloading Corrupted Images
by derby (Abbot) on May 10, 2007 at 15:42 UTC

    Errr ... a link to one that you think is corrupted would be a better -- the one's in the OP download fine for me.

    -derby
      The one in the code is one that is corrupted when I download it. Here's a link to it. It works fine in a browser, but in the code I only get garbage.

        Well it's not your code. The file downloaded fine for me using your code. I'm using version 1.41 of LWP::Simple. Maybe a permssion problem? You can check the return value of the getstore call.

        -derby