in reply to Printing Random Image in HTML
The way to call it from an HTML document would be something like the following:#!/usr/bin/perl -w use strict; use LWP::Simple; use vars qw($in_file @imgdata @imgs $num $id $image $url $type $format $out_file); $in_file = 'ads.dat'; @imgdata = <DATA>; @imgs = grep {/\|(?:internal|partner)$/} @imgdata; $num = int(rand($#imgs) +1); ($id, $image, $url, $type) = split /\|/, $imgs[$num]; $url = $url . $image; $format = $1 if $image =~ /\.(\w+)$/; $format = 'jpeg' if $format =~ /^jpe?g$/; $out_file = get($url); print "Content-type: image/$format\n\n"; print $out_file; __DATA__ 1|/images/dibona_sm.gif|http://perlmonks.org|internal 2|/images/usermonkpics/ovidmonk.gif|http://perlmonks.org|partner 3|/pics/gol.gif|http://www.f.com|payed
The only problem that I see with it is that you can't specify the height and width tags, but being able to embed it in HTML instead of just serving an image by itself should give you greater flexibility. (This code can probably be simplified further. I just threw it together).<img src="http://www.somedomain.com/cgi-bin/myscriptname.cgi" alt="Ran +dom image">
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid) RE: Printing Random Image in HTML
by markjugg (Curate) on Jul 04, 2002 at 14:42 UTC |