CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
create image?

 



mike_robb
Novice

Mar 19, 2001, 4:56 PM

Post #1 of 3 (230 views)
create image? Can't Post

I was wondering what the easiest method is to have an HTML tag for an image call a perl script and have it return the image.

<html><head></head><body>
<img src="/cgi-bin/some.cgi">
</body></html>

where the image file on the server already exists in say a png format:
/images/pic.png

What perl script would I use (how do I set the mime type?) and how do I pass through a image formatted file?

TIA!


------

here is what i found....


#!/usr/local/bin/perl
#
# counter cgi
# 2000 Jackie Hamilton - http://www.cgi101.com/
#
# this cgi increments a counter in a file, then returns a gif image.
# (use either a small, 1-pixel "invisible" image, or your logo or something.)
# HTML code to call this:
#
# <img src="counter.cgi">
#
# this is good for use as a "hidden" counter within a page.
#
# note: be sure that the counter file is set WRITABLE by the httpd
# daemon owner or group. in Unix you'll need to 'chmod 775 countfile'
# or possibly 'chmod 777 countfile'.

$countfile = "cgicount";
$giffile = "small.gif";

$count = `cat $countfile`;
chop($count);
$count = $count + 1;
open(INF,">$countfile");
print INF "$count\n";
close(INF);

# if you're using a JPEG instead of a GIF, you should change this
# line to print type image/jpg.
print "Content-type:image/gif\n\n";
@gifdata = `cat $giffile`;
print @gifdata;

# the end.




(This post was edited by mike_robb on Mar 19, 2001, 4:21 PM)


Aquilo
journeyman

Mar 20, 2001, 7:26 AM

Post #2 of 3 (221 views)
Re: create image? [In reply to] Can't Post

When putting images on a page I dont use the mime-type
but you can!

Code
#!/usr/local/bin/perl 

$image_dir = "http://site.com/images";

#>http://site.com/cgi-bin/image/script.pl?Image=any_image.gif|png|jpg...
$image_file = "$in{'Image'}"; #<= requires parse

#>http://site.com/cgi-bin/image/script.pl?any_image.gif|png|jpg...
#$image_file = "$ENV{'QUERY_STRING'}"; #<= does not require parse

$set_image = "$image_dir\/$image_file";
&image;

sub image {
print "Location: $set_image\n\n";
exit;
}
1;

# print "Content-type:image/gif\n\n";
# print "Content-type:image/jpg\n\n";
# print "Content-type:image/jpeg\n\n";
# print "Content-type:image/png\n\n";

=
http://www.xtram.tc/communities/?Community=Shake&Bake=1.gif




mike_robb
Novice

Mar 20, 2001, 7:34 AM

Post #3 of 3 (220 views)
Re: create image? [In reply to] Can't Post

thanks for the nifty script!:)


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives