USANet Creations
Users Support and Discussion Areas

NOTE: Always state the software package you have
when asking questions so you will get the correct answer,
as it does make a big difference in the answers you'll get!

| Main Site Home Page | Forums Home Page |

Subject: "Real Thumbs with ImageMagick"   Page 1 | 2 | 3 | Previous Topic | Next Topic
nonePrinter-friendly copy    
Conferences MakeBid Auction user submitted addons and updates Topic #195
Reading page 1 of 3 pages
AgentX
unregistered user
Jul-01-04, 08:59 PM (CST)
 
"Real Thumbs with ImageMagick"
 
   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]


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
AgentX
unregistered user
Jul-02-04, 09:35 AM (CST)
 
1. "RE: Real Thumbs with ImageMagick"
 
   If you only want thumbs making when the user elects to put an image in the gallery you need to replace the three instances of this code in stage 6 & 9:

[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]

with:

[font color="red"]if ($form{'GALLERY'} eq "Yes" ) {
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]


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
NIBB
unregistered user
Jul-02-04, 11:49 AM (CST)
 
2. "RE: Real Thumbs with ImageMagick"
 
   Great that should reduze download time, where do users download ImageMagick???


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
richardadmin
unregistered user
Jul-02-04, 03:20 PM (CST)
 
3. "RE: Real Thumbs with ImageMagick"
 
   >Great that should reduze download time, where do users download
>ImageMagick???

Your hosting server has to have ImageMagick installed (not something you can install) most servers have ImageMagick installed, if yours does not you need to request them to install it, or you will have to find a new hosting server that has this feature.


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
Len
unregistered user
Jul-14-04, 09:19 AM (CST)
 
4. "RE: Real Thumbs with ImageMagick"
 
   Hi AgentX
I have thumb looking images on my site
is there a way I can just change the auction.pl, config.pl
and selleredit.pl files to show thumbnails your way?
the script I used was.


===============================================================
Find the new instructions below to show the auction items image
in the listings if the user selected the gallery featured listings:
This is for the auction deluxe versions only!
===================================================

In the auction.pl file under the displist sub, displistfeat sub, displistnew sub, displisthot sub, displistgone sub, displistclose sub, displistdutch sub,

Find these lines:

my $reservepricemet = "<IMG SRC=\"$config{'reservemetpic'}\">" if ($bid >= $reserve) && ($reserve > '0.00') && ($dutch eq 'no');

Now past this line just after the above found line:

my $imagedisp = "<IMG SRC=$image1 BORDER=\"0\" WIDTH=\"75\">" if (($image1 ne "") && ($gallery eq "Yes"));

If you wont to display a image in the listings if the gallery was not chosen then use this line:

my $imagedisp = "<IMG SRC=$image1 BORDER=\"0\" WIDTH=\"75\">" if ($image1 ne "");


Now find these lines:

print "<TD>$config{'displistfont'}<A HREF=$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file>$grabberpic $mytitle</a></td>";

Now add the below to the above line you just found just before the $grabberpic :

$imagedisp

Now it should look sonething like this:

print "<TD>$config{'displistfont'}<A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file>$imagedisp $grabberpic $mytitle</a></td>";


Best Regards
Len


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
AgentX
unregistered user
Jul-14-04, 01:17 PM (CST)
 
5. "RE: Real Thumbs with ImageMagick"
 
   Hi Len,

If you make the listed changes to auction.pl, config.pl, selleredit.pl etc., you would use the code in stage 11 for displaying thumbs in displist sub, displistfeat sub, displistnew sub, displisthot sub, displistgone sub, displistclose sub, displistdutch sub etc.

Hope this answers your question?


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
Len
unregistered user
Jul-14-04, 02:22 PM (CST)
 
6. "RE: Real Thumbs with ImageMagick"
 
   Hi AgentX
Do you have a copy of all of the standard Auction Deluxe
file's up-dated with the changes you have made?.
I am happy with the way my site looks at the moment
displaying the thumbnail like images but if they could be real thumbnails displayed in the same way as they are now on my site
that would be excellent!
Many thanks for any help!
Best Regards
Len
p.s.
Please feel free to e-mail me at
admin@auction1.co.uk



  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
AgentX
unregistered user
Jul-14-04, 03:37 PM (CST)
 
7. "RE: Real Thumbs with ImageMagick"
 
   Hi Len,

Unfortunately all my files are radically customized to suit my site. Not just cosmetics but I've altered several functions. I don't use displistfeat sub, displisthot sub, displistdutch or any subcategories for example, so I don't think they'd be much use to you.

I keep a copy of the original untouched files and if Richard does an update I use ExamDiff (free trial version) to see exactly what's changed. Then I cut and paste the changes I want into my custom files. It still goes pear-shaped sometimes, but without ExamDiff there'd be no hope of converging my files with the latest updates.

I've listed all the changes you need. I know it looks a bit daunting (took me weeks to get it right!) but now it's all down in black and red it shouldn't be too hard. Easy for me to say!


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
Len
unregistered user
Jul-14-04, 03:44 PM (CST)
 
8. "RE: Real Thumbs with ImageMagick"
 
   Hi AgentX
No worries,
Many thanks for all your kind help!
Best Regards
Len


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
Len
unregistered user
Jul-15-04, 06:57 AM (CST)
 
9. "RE: Real Thumbs with ImageMagick"
 
   Hi AgentX
Can you tell me how to update this part of my config.pl file
if you can just fill-in what needs to be added that would be excellent!
Many thanks.
Best Regards
Len

#-#####################################
# Photo Uploader configuration section
#-#####################################

## This should point to the upload image directory in your
## html document root dir no trailing slash.
## on Windows NT/2000 servers only you need to specify
## the drive letter (c:,d:,e:) with the server path example:
## $config{'imagebase'} = '/your/server/path/auct-photos';

$config{'imagebase'} = '/home/lgoundry/public_html/auct-photos';

## URL of Image Directory
$config{'imageurl'} = 'http://www.bid-alot.co.uk/auct-photos/';

## URL of Temp Image Directory
$config{'imagetempurl'} = 'http://www.bid-alot.co.uk/auct-photos/temp/';

## URL Path to the yourphoto image uploader
$config{'yourphotourl'} = 'http://www.bid-alot.co.uk/cgi-bin/auction/yourphoto.pl';

## Delete auction item images after X Days
## starts from the time the image was uploaded
## NOTE if you change this setting make sure you change it
## in the yourphoto.pl file as well or there will be problems

$config{'delimagedays'} = 90;

## For Display only the max image file size in KB to upload.

$config{'limit'} = 360;


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote
Len
unregistered user
Jul-15-04, 07:02 AM (CST)
 
10. "RE: Real Thumbs with ImageMagick"
 
   Hi AgentX
I should have said, my thumbnail path will be.
http://www.bid-alot.co.uk/auct-thumbs
Best Regards
Len


  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote


Page 1 | 2 | 3 | Conferences | Topics | Previous Topic | Next Topic
Rate this topic Rate this topic