OK - here goes - while it's still fairly clear in my mind: Complete thumbnails for Auction Deluxe Version 400D etc. using ImageMagick.(With a few small changes it also works fine for shoppingmall etc.)
[center][b]What it does:[/b][/center]
It creates optimised thumbs from jpgs, gifs and bmps from images your users either upload from their computers or link to via URLs.
By creating "low fat" mini images, it greatly reduces download time and bandwidth useage on your image pages, galleries etc., allowing you to put small images with all your auction listings.
Thanks to Matt Chiles at auctionbrick.com for the code and patiently steering me through it and to Jay at specialengines.com for the ImageMagick code.
[center][u][h4]INSTRUCTIONS[/h4][/u][/center]
[font size="4" color="#CC3300"][b]1.[/b][/font] Before wasting time on this, let's make sure we have the neccessary ImageMagick module installed on the server.
Ask your host - or better still, run a test script.
Download test script: em-test.cgi
Directions:
- Extract the em-test.cgi file and upload it to your server.
- Set it's permissions to 755
- Execute the script
If you see this: Image::Magick (PerlMagick) Perl Module: Installed
Rejoice! We're set to go.
[font size="4" color="#CC3300"][b]2.[/b][/font] Make a thumbs folder next to your photos folder. Upload it and chmod 777.
[font size="4" color="#CC3300"][b]3.[/b][/font] In the Photo Uploader configuration section of config.pl add this with your paths and url's. Substitute "my-domain" with your domain name without the ".com" etc.
[font color="red"]$config{'thumbbase'} = '/mypath/public_html/auction/assets/thumbs';
$config{'defaultthumb'= 'http://www.my-domain.com/auction/assets/images/no-image.gif';
$config{'site'} = 'my-domain';
## URL of Thumbs Directory
$config{'thumburl'} = 'http://www.my-domain.com/auction/assets/thumbs/';[/font]
[font size="4" color="#CC3300"][b]4.[/b][/font] Create and upload the no-images.gif (displayed when no thumb is available). Make it whatever size you want your thumbs to be.
[font size="4" color="#CC3300"][b]5.[/b][/font] At the top of auction.pl after:
[font color="red"]use CGI qw/:standard/;[/font]
paste:
[font color="red"]use Image::Magick;[/font]
[font size="4" color="#CC3300"][b]6.[/b][/font] Now to create the thumbs from off-site image url's. In auction.pl, (sub procnew) immediately after:
[font color="red"]### End Accounting Setup ###[/font]
paste:
[font color="red"]### Makes a thumb for images hosted off site:
my $new_thumb_name;
if (($form{'IMAGE1'} !~ /http\:\/\/www\.$config{'site'}\.com/) && (($form{'IMAGE1'} =~ /.\jpg/g) || ($form{'IMAGE1'} =~ /.\bmp/g) || ($form{'IMAGE1'} =~ /.\gif/g))) {
my $newimage = ($config{'delimagedays'} * 86400 + time);
sleep 2;
$new_thumb_name = "$newimage.jpg"; ## gets a new name for the offsite image
use LWP::Simple;
my $content; ## Gets the image from offsite
$content = getstore("$form{'IMAGE1'}","$config{'imagebase'}/temp/$new_thumb_name");
{
my ($q, $x);
$q= Image::Magick->new;
$x= $q->Read("$config{'imagebase'}/temp/$new_thumb_name");
warn "$x" if "$x";
$x = $q->Resize(geometry=>'100x100');
warn "$x" if "$x";
$x=$q->Write("$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
{
my ($q, $x);
$q= Image::Magick->new;
$x= $q->Read("$config{'imagebase'}/temp/$new_thumb_name");
warn "$x" if "$x";
$x = $q->Resize(geometry=>'100x100');
warn "$x" if "$x";
$x=$q->Write("$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 <a href=mailto:$config{'admin_address'}>$config{'admin_address'}</a> that a thumb could not be created for this auction.</b></center><br>";
}
}
## 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{'IMAGE1'} = "$config{'imageurl'}";
}
}
#########end code###########[/font]
[font color="green"][b]Note:[/b]
Remember to put an extra "\" before the dot if your domain name ends \.co\.uk (for example) on this line:
if (($form{'IMAGE1'} !~ /http\:\/\/www\.$config{'site'}\.com/) &&
Uncomment these lines for testing purposes:
#print "<center>A local thumb was made for your image.</center>";
and
#print "<center>A local thumb was made for your image on the second try.</center>";
Set geometry=>'100x100' to the thumb size you want.[/font]
[font size="4" color="#CC3300"][b]7.[/b][/font] Below this, find the line starting:
[font color="red"]print NEW[/font]
In this line, replace:
[font color="red"]$form{'IMAGE1'}\n[/font]
with:
[font color="red"]$form{'IMAGE1'}$new_thumb_name\n[/font]
[font size="4" color="#CC3300"][b]8.[/b][/font] In auction.pl (sub new) after:
[font color="red"]<INPUT NAME=IMAGE4 VALUE=\"$image4\" TYPE=TEXT SIZE=55>[/font]
paste:
[font color="red"]<INPUT TYPE=HIDDEN NAME=LOCALHOST VALUE=yes>[/font]
[font color="green"][b]Note:[/b]
This forces the script to save a copy of off-site linked images to your photo directory. That's my preference. Otherwise set "VALUE=no" or as Matt suggests, make it a user option.[/font]
[font size="4" color="#CC3300"][b]9.[/b][/font] Now let's create thumbs from images uploaded from user's computer. In auction.pl (sub new) after:
[font color="red"]File::Copy::move ("$config{'imagebase'}/temp/$form{'UPIMAGE1'}", "$config{'imagebase'}/$form{'UPIMAGE1'}") or oops ("Please notify the site admin that the image cannot be copied from the temp dir to the photo dir.");[/font]
paste:
[font color="red"]{
my ($q, $x);
$q= Image::Magick->new;
$x= $q->Read("$config{'imagebase'}/$form{'UPIMAGE1'}");
warn "$x" if "$x";
$x = $q->Resize(geometry=>'100x100');
warn "$x" if "$x";
$x=$q->Write("$config{'thumbbase'}/$form{'UPIMAGE1'}");
}[/font]
[font color="green"][b]Note:[/b]
You should now have two closing brackets before the next line thus:
}
} if ($form{'UPIMAGE2'} ne "")[/font]
[font size="4" color="#CC3300"][b]10.[/b][/font] Now we need a bit of code to delete the thumbs when the auction items are removed.
In selleredit.pl immediately after this line:
[font color="red"]unlink "$config{'imagebase'}/$image1";[/font]
add this line:
[font color="red"]unlink "$config{'thumbbase'}/$image1";[/font]
Now make the same change in admin.pl
[font size="4" color="#CC3300"][b]11.[/b][/font] Now to display the thumbs we just made. We'll do it in dispall.pl but the method can be applied to the other dispall files, the various list displays in auction.pl and dispcat7.pl or whichever you're using.
After this line:
[font color="red"]my $timeremain = time_remain($file);[/font]
paste:
[font color="red"]### checks to see if image is local or not for thumb
if ($image1 =~ /http\:\/\/www\.$config{'site'}\.com/) {
$image1 =~ s/photos/thumbs/; #original line to redirect to thumb file
}
elsif ($image1 =~ /:::/) {
$image1 =~ s/(.*?)::://; ### pulls off thumb file
$image1 = "$config{'thumburl'}/$image1";
}
else {
$image1 = "$config{'defaultthumb'}";
}
my $imagedisp = "<IMG SRC=\"$image1\" BORDER=\"0\" WIDTH=\"50\" alt=\"Click to visit item\">";[/font]
Replace:
[font color="red"]print "<TD>$buyitnow$new$image$hot$end$dutchicon$reserveprice$reservepricemet$filler</TD>";[/font]
with:
[font color="red"]print "<TD>$buyitnow$new$hot$end$dutchicon$reserveprice$reservepricemet$filler<table border=\"1\" cellspacing=\"1\" cellpadding=\"0\"><tr><td bordercolor=\"#ECE9D8\"><A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file onMouseOver=\"window.status='Visit the item';return true\" onMouseOut=\"window.status='Done';return true\">$imagedisp</a></td></tr></table></TD>";[/font]
[font color="green"][b]Note:[/b]
Set WIDTH= as appropriate. Setting it at least a little smaller than the thumbs you've made gives a sharper image.
I've added a little frame and status bar mouse-over message etc. in the last line (non-vital embelishments), but "$imagedisp" is the crucial bit to show your thumb.
To make the thumb sit nicely on this page, I've also changed:
print "<TR BGCOLOR=$config{'boldbackground'}>";
}
else {
print "<TR BGCOLOR=$itemrowcolor>";
to:
print "<TR BGCOLOR=\"$config{'boldbackground'}\" align=\"center\">";
}
else {
print "<TR BGCOLOR=\"$itemrowcolor\" align=\"center\">";[/font]
[font size="4" color="#CC3300"][b]12.[/b][/font] Finally, let's put a thumb at the top of the auction item page. Not essential because we could use a small version of Image1 here, but a quicker top image makes the page look faster. We need something slightly different here. This is a bit belt & braces, but it works. In auction.pl (sub dispitem) after this line:
[font color="red"]my $backto = &backto;[/font]
paste:
[font color="red"]my $imagedisp = "<IMG SRC=$image1>" if ($image1);
$imagedisp =~ s/:::(.*?)\>/\>/g; ### pulls off thumb file stuff
my $thumb = $image1;
### checks to see if image is local or not for thumb
if ($thumb =~ /http\:\/\/www\.$config{'site'}\.com/) {
$thumb =~ s/photos/thumbs/;
}
elsif ($thumb =~ /:::/) {
$thumb =~ s/(.*?)::://; ### pulls off thumb file
$thumb = "$config{'thumburl'}/$thumb";
}
else {
$thumb = "$config{'defaultthumb'}";
}[/font]
and after:
[font color="red"]my $location = $selleradd3;[/font]
paste:
[font color="red"]my $smallpic;
if ($thumb) {
$smallpic = "<table border=\"2\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#990000\"><tr>
<td><a href=\"$ENV{'SCRIPT_NAME'}?category=$form{'category'}&item=$form{'item'}#DESC\" onMouseOver=\"window.status='See full item details';return true\" onMouseOut=\"window.status='Done';return true\"><IMG SRC=\"$thumb\" BORDER=\"0\" WIDTH=\"70\" alt=\"Show item details\"></a></td></tr></table>"; }
if ($thumb eq ""){
$smallpic = "<a href=\"$ENV{'SCRIPT_NAME'}?category=$form{'category'}&item=$form{'item'}#DESC\" onMouseOver=\"window.status='See full item details';return true\" onMouseOut=\"window.status='Done';return true\"><IMG SRC=\"$config{'descicon'}\" BORDER=\"0\" WIDTH=\"70\" alt=\"Show item details\"></a>"; }[/font]
[font color="green"][b]Note:[/b]
Again lots of extra border stuff here which you may care to do without, but "$smallpic" is now what you use to display a thumb below on your auction item page.
The "descicon" image is identical to "no-image.gif" mentioned earlier, and means that we get our custom image when there's no image posted or no thumb available.
For completion, you could also use the above in sub viewcloseddisp (also in auction.pl) and in dispallclosed.pl.[/font]