It can be done! I stumbled across the way to do it while I was
surfing over at perlmonks the other day looking for user file
uploading solutions. And the best part is it uses native perl, plus
whatever thumbmaking process you normally use - ImageMagick or Unix
pnmscale method.OK, the trick is the perl "getstore" function, which "gets" a file
specified from anywhere on the internet and "stores" it in your
computer. Obviously this requires that the file you get isn't in a
protected directory or else there would be security holes all over
everything.
Here is the way I use it (using the UNIX/LINUX pnmscale method,
easily modifible to ImageMagick for those using that). Insert this
code [i]before[/i] you write the new auction file - I insert it just
before this line: " my @seconds = qw/0 1 2 3 4/; "
You will need to add a $config{'site'} to your config.pl file, where
it equals your basic site name ("auctionbrick" for me):
### Makes a thumb for images hosted off site:
my $new_thumb_name;
if (($form{'IMAGE'} !~ /http\:\/\/www\.$config{'site'}\.com/) && ($form{'IMAGE'} =~ /.\jpg/g)) { # checks to make sure this isn't a relist that is already hosted locally
my $newimage = ($config{'delimagedays'} * 86400 + time);
sleep 2; # so you don't get duplicate image names
$new_thumb_name = "$newimage.jpg"; ## gets a new name for the offsite image
use LWP::Simple;
my $content;
## Gets the image from offsite, puts it in your temp image directory
$content = getstore("$form{'IMAGE'}","$config{'imagebase'}/temp/$new_thumb_name");
## Converts the image to a thumb, saves it onsite.
## Replace below with ImageMagick method if you use that
system("ulimit -u 5; djpeg -pnm $config{'imagebase'}/temp/$new_thumb_name | pnmscale -xysize 100 100 | cjpeg >\"$config{'thumbbase'}/$new_thumb_name\"");
## Test to see that the thumb was properly created. Tries again if failed.
if ((-e "$config{'thumbbase'}/$new_thumb_name") && ((-s "$config{'thumbbase'}/$new_thumb_name") > 0)) {
print "<center>A local thumb was made for your image.</center>";
}
else {
## Converts the image to a thumb, saves it onsite, 2nd try.
sleep 5; ## rests for 5 seconds
system("ulimit -u 5; djpeg -pnm $config{'imagebase'}/temp/$new_thumb_name | pnmscale -xysize 100 100 | cjpeg >\"$config{'thumbbase'}/$new_thumb_name\"");
## Test to see that the thumb was properly created, 2nd try test.
if ((-e "$config{'thumbbase'}/$new_thumb_name") && ((-s "$config{'thumbbase'}/$new_thumb_name") > 0)) {
print "<center>A local thumb was made for your image on the second try.</center>";
}
else {
## Thumb process didn't work message
print "<center><B>Please notify $config{'sitename'} at <a href=mailto:$config{'admin_address'}>$config{'admin_address'}</a> that a thumb could not be created for this auction.</b></center>";
}
}
## Deletes the offsite image from your site, leaving only the thumb if unchecked
if ($form{'LOCALHOST'} != "yes") {
unlink ("$config{'imagebase'}/temp/$new_thumb_name");
$new_thumb_name = ":::$new_thumb_name"; ## adds ::: demarker for writing auction listing file
}
else {
File::Copy::move ("$config{'imagebase'}/temp/$new_thumb_name","$config{'imagebase'}/$new_thumb_name");
$form{'IMAGE'} = "$config{'imageurl'}";
}
}
And you will need to modify the $form{'IMAGE'} in your print NEW line
for printing a new auction listing as follows, inserting $new_thumb_name:
\n$form{'DESC'}\n$form{'IMAGE'}$new_thumb_name\n
My method above will save a copy of the image on your site and use
the local image for the auction instead of the off-site link
[i]unless[/i] the user unchecks a box in the auction form. This
code needs to be inserted in your [b]sub new[/b] just after the
text box for inserting the link to the off site image:
<BR>
<font size=-1 color=dd0000><INPUT TYPE=CHECKBOX NAME=LOCALHOST VALUE=yes CHECKED> <I>Leave this checked to have a copy of the image placed locally on $config{'sitename'} for use with this auction.</i></font>
If the user elects to have the image not stored on your site (except
the thumb, of course) then the image will be saved like this in the
auction field: [b]http://www.theirsite.com/image.jpg:::1234567890.jpg
[/b] where 1234567890.jpg is your local name for the thumb. Now to
pull the image out when you need to use it (for when it is stored off
of your site) you will need to add code similar to this wherever the
thumb or the image is used:
Code to pull out a thumb (used frequently):
### checks to see if image is local or not for thumb
if ($image =~ /http\:\/\/www\.$config{'site'}\.com/) {
$image =~ s/photos/thumbs/; #original line to redirect to thumb file
}
elsif ($image =~ /:::/) {
$image =~ s/(.*?)::://; ### pulls off thumb file
$image = "$config{'thumburl'}/$image";
}
else {
$image = "$config{'defaultthumb'}";
}
Code to pull out an image and a thumb (used only in auction displays):
my $imagedisp = "<IMG SRC=$image>" if ($image);
$imagedisp =~ s/:::(.*?)\>/\>/g; ### pulls off thumb file info from the image url
A couple other things to note - this code only works for jpg images
since the UNIX method only works for jpg images, but you should be
able to modifiy the jpg check for whatever images you are able to
turn into thumbs using the ImageMagick method. Remember that we
pretty much are all using different methods to make, store and call
images by now if you have been messing with thumbs already. So look
at this code with a critical eye to modifiy it for your system.
Good luck!
-Matt :)
www.auctionbrick.com