####
#!/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,$password) 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:-');