I have a script which contains several links like so:
<img src="cgi-bin/image_serve.cgi?full+124236+pc_img1">
where the arguments change for every link.
'full' is the size of the view, '124236' is the ID (and the primary key in the database) and 'pc_img1' is the location.
The script returns an image, which is then put into the page on the fly. There are multiple different images on the page, all presented by the same program.
My concerns is that calling the 'image_serve.cgi' multiple times from the same page with different arguments is causing some kind of problem. Perhaps it simply takes too long for some of the images and the server times out?
When viewing the page with the multiple calls, some images show up, some do not and show broken link placeholders. This changes at random and will differ each time the script is run. Also, occasionally, all images show up. After the page is done loading, one can right-click and "Show Picture" on the images and they will display, so the data does exist.
The code for my 'image_serve.cgi' is below:
#!/usr/bin/perl
BEGIN {
$|=1;
use CGI::Carp('fatalsToBrowser');
}
use CGI qw(:all);
use DBI;
use DBD::mysql;
use Image::Magick;
my $database = "###";
my $username = "###";
my $password = "###";
my $hostname = "###";
my $tbl = "listings";
my $query = new CGI;
my $location = $ARGV[0];
my $mls_id = $ARGV[1];
my $img = $ARGV[2];
my $dbh = DBI->connect("DBI:mysql:$database:$hostname",$username,$pass
+word) or die "Unable to connect to listings Database: $DBI::errstr\n"
+;
my $sql = "SELECT $img FROM listings WHERE pc_mls_id = $mls_id";
my $sth = $dbh->prepare($sql) or die "Couldn't prepare: $DBI::errstr\n
+";
$sth->execute;
my $ref = $sth->fetchrow_hashref;
my $raw_img_data = $$ref{$img};
$sth->finish;
$dbh->disconnect;
my $image = Image::Magick->new;
open(IMAGE, $raw_img_data);
$image->Read(file=>\*IMAGE);
close(IMAGE);
my ($x,$y);
if ($location eq "detailed"){
$x = 250;
$y = 226;
}
if ($location eq "med"){
$x = 150;
$y = 113;
}
if ($location eq "small"){
$x = 75;
$y = 57;
}
$image->Resize(width=>$x,height=>$y);
print "Content-type: image/jpeg\n\n";
$image->Write('jpg:-');
Anything glaring I'm missing, or is the problem on the server or client end, and not Perl's problem?
Thanks,
cidaris
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.