in reply to Re: showing an image downloaded with LWP::Simple
in thread showing an image downloaded with LWP::Simple

How come Internet Explorer cannot view the image? Thanks for your help.
  • Comment on Re^2: showing an image downloaded with LWP::Simple

Replies are listed 'Best First'.
Re^3: showing an image downloaded with LWP::Simple
by Joost (Canon) on Sep 08, 2006 at 18:35 UTC
      Thanks again for your assistance. Here is the code below:

      #!/usr/local/bin/perl #Warn browser that HTML is coming print "Content-type: text/html\n\n"; print header; print STDOUT "<html>\n<head>\n"; print STDOUT "<title></title>\n"; print STDOUT "</head>\n"; print STDOUT "<body>\n"; use LWP::Simple; print $content = get("http://www.nhc.noaa.gov/storm_graphics/AT06/refr +esh/AL0606W5+gif/144631W_sm.gif"); print STDOUT "</body>\n"; print STDOUT "</html>\n";

      Basically, I just want to display the image when I go to the link.

      Edit: g0n - code tags

        A couple of points:
        • ugly hacks aside, you can't just dump image data inside HTML, even if you do it from a script. You should use img (or object) tags.
        • There is no link in your HTML so I don't know what link you're talking about.
        • If you want to show a remote image, what's wrong with <img src="http://www.nhc.noaa.gov/storm_graphics/AT06/refresh/AL0606W5+gif/144631W_sm.gif"> ?
        • Please read writeup formatting tips - or at least use <code> tags around your code.
        • If you really really want to, use something like this: (in your html): <img src="/path/to/script.cgi"> and (in your script.cgi):
          #!/usr/bin/perl -w use strict; use LWP::Simple; print "Content-type: image/gif\n\n"; binmode STDOUT; getprint "http://www.nhc.noaa.gov/storm_graphics/AT06/refresh/AL0606W5 ++gif/144631W_sm.gif";
        You haven't told the browser that there is an image coming. The only MIME type that you have given is "text/html", you need to drop all of the html and tell the browser to expect "image/gif". Take a look at the Downloading a file discussion, where there is discussion of headers similar to what you need to set.
        Hint: You should take a look at the headers that you get back when you download the image from www.nhc.noaa.gov, and probably hand them back, or directly link to the noaa image from your existing html, like this:
        print STDOUT "<html>\n<head>\n"; print STDOUT "<title></title>\n"; print STDOUT "</head>\n"; print STDOUT "<body>\n"; print STDOUT "<img src=\"http://www.nhc.noaa.gov/storm_graphics/AT06/r +efresh/AL0606W5+gif/144631W_sm.gif\"></img>\n"; print STDOUT "</body>\n"; print STDOUT "</html>\n";
        Update: see the responses, above, from Joost and Melly.