Gossamer Forum
Home : General : Perl Programming :

Displaying image through cgi script!

Quote Reply
Displaying image through cgi script!
I am successfully able to grab an external page through my cgi file.
Can any body help me to grab an image through a cgi file and when the cgi file is called it should display only the image.
I wanted this type of stuff coz i don't want my visitor to know from where i m grabbing the image. Even if they look at the source it should show the cgi-script path.

Best Regs
JackofNone

Quote Reply
Re: Displaying image through cgi script! In reply to
How about the following for image, $image:


use LWP::MediaTypes qw (guess_media_type);

my $mime = guess_media_type ($image);

print "Content-type: $mime\n\n";
open (FILE, $image) || die ("Cannot open $image - $!");
print <FILE>;
close (FILE);



Dan Cool


Quote Reply
Re: Displaying image through cgi script! In reply to
Dan,
i just defined the value for the $image and when i ran the script it showed me nothing. "The document contains no data". Can you tell me what and where i have to change the value in the code provided by you.
I want to grab a .gif file

Thanks in advance
Best Regs
JackofNone

Quote Reply
Re: Displaying image through cgi script! In reply to
Can you post your script (or URL to text version if too large - i.e., > 100 lines code) along with URL to where it is implemented.


Dan Cool


Quote Reply
Re: Displaying image through cgi script! In reply to
Dan,
Here is what i m using,

#!/usr/bin/perl

use LWP::Simple;

$image = 'http://d.eimg.com/f/EXCITE/MESP/gifts-dvdplayers20001121194823.gif';

print "Content-type: image/gif\n\n";
open (FILE, $image) || die ("Cannot open $image - $!");
print <FILE>;
close (FILE);


I have changed your line of code which gets the mime type as i know it.
Where am i going worng?
Thanks in advance
Best Regs
JackofNone

Quote Reply
Re: Displaying image through cgi script! In reply to
1. No need to use LWP module. Delete line.
2. Use path and not URL to image on your server.

Or are you trying to pull an image from another server? Then that's a different story using the LWP::Simple module. And if the case, do you have expressed permission of the other site to pull content from their server? At any rate to retrieve and display an image from another server, use the following code (using as an example the URL you provided):


use LWP::Simple;
$image = get ('http://d.eimg.com/f/EXCITE/MESP/gifts-dvdplayers20001121194823.gif');
print "Content-type: image/gif\n\n";
print $image;



Dan Cool
Quote Reply
Re: Displaying image through cgi script! In reply to
Thanks a lot Dan!
Its working!
Actually i m not breaking any law. I m just extracting pictures from my other site and dont want my users know about it.
Its basically an adult website.

Thanks a lot Buddy!
Best Regs
JackofNone