Connecting Tech Pros Worldwide Forums | Help | Site Map

Create thumbnails with clickable links XYZ

Krustov
Guest
 
Posts: n/a
#1: Oct 30 '06
The question of how to create thumbnails with clickable links gets asked
on this newsgroup every so often - like clock work .

Just really posing this script here for google to archive it & so users
can be pointed to it in the future via a link to google groups .



<html>
<head>
<title>thumbnails.php</title>
</head>

<style type="text/css">

body {margin-bottom : 0px;margin-left : 0px; margin-right : 0px;
margin-top : 0px;}

A:link {text-decoration: none;}
A:visited {text-decoration: none;}
A:active {text-decoration: none;}
A:hover {text-decoration : underline;}

..backy{background-color: #FFEEFF;}

..gap1{font-size: 1px;}
..gap2{font-size: 2px;}
..gap3{font-size: 3px;}
..gap4{font-size: 4px;}
..gap5{font-size: 5px;}
..gap6{font-size: 6px;}
..gap7{font-size: 7px;}
..gap8{font-size: 8px;}
..gap9{font-size: 9px;}

..tap
{
color : Black; background-color: #F9FBFB;
font-size : 20pt; font-family : Arial;
padding-left: 22px; padding-right: 22px; padding-top: 3px; padding-
bottom: 3px;
border: 1px solid #CFD1F1;
}

..box
{
background-color: #FFEFFF;
padding-left: 2px; padding-right: 2px; padding-top: 2px; padding-bottom:
2px;
border: 1px solid #FEDAFE;
}

..bar
{
background-color: #F5DDFF;
padding-left: 5px; padding-right: 5px; padding-top: 0px; padding-bottom:
3px;
border: 1px solid #DADBD1;
}

..thumbnav
{
color: #000000; background-color: #F4DEDE;
font-size: 10pt; font-family: Arial; text-align: center;
padding-left: 9px; padding-right: 9px; padding-top: 4px; padding-bottom:
4px;
}

..thumbnav:hover
{
text-decoration: none;
color: #000000; background: #FFFFC0;
}

..mma{color : Maroon; font-size : 8pt;font-family : Arial;}
..mmb{color : Maroon; font-size : 10pt;font-family : Arial;}
..mmc{color : Maroon; font-size : 12pt;font-family : Arial;}
..mmd{color : Maroon; font-size : 14pt;font-family : Arial;}

..bba{color : Black; font-size : 8pt;font-family : Arial;}
..bbb{color : black; font-size : 10pt;font-family : Arial;}
..bbc{color : Black; font-size : 12pt;font-family : Arial;}
..bbd{color : Black; font-size : 14pt;font-family : Arial;}

..nna{color : Navy; font-size : 8pt;font-family : Arial;}
..nnb{color : Navy; font-size : 10pt;font-family : Arial;}
..nnc{color : Navy; font-size : 12pt;font-family : Arial;}
..nnd{color : Navy; font-size : 14pt;font-family : Arial;}

..rra{color : Red;font-size : 8pt;font-family : Arial;}
..rrb{color : Red;font-size : 10pt;font-family : Arial;}
..rrc{color : Red;font-size : 12pt;font-family : Arial;}
..rrd{color : Red;font-size : 14pt;font-family : Arial;}

</style>

<body class="backy">

<?php

$weed=basename($_SERVER['PHP_SELF']);

$dir="test/images"; $columns=6;

$ext=".jpg";

# .jpg .gif .png , You can use any of these 3 image extensions , But not
more than one at a time .

$what=$_REQUEST['filex']; $what=strtolower($what);

if ($what<>"")
{
if ($what=="jpg") {$ext=".jpg";}
if ($what=="gif") {$ext=".gif";}
if ($what=="png") {$ext=".png";}
}

$thumbext="_thumb" . "$ext";

$whatupper=str_replace(".","",$ext); $whatupper=strtoupper($whatupper);

?>

<div align="center" class="gap9">&nbsp;</div>

<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="tap">THUMBNAILS - <?php print $whatupper; ?></td>
</tr>
</table>

<div align="center" class="gap5">&nbsp;</div>

<table border="0" cellspacing="5" cellpadding="0" align="center">
<tr>
<td><a href="<?php print $weed; ?>?filex=jpg" class="thumbnav">&lt; JPG
&gt;</a></td>
<td><a href="<?php print $weed; ?>?filex=gif" class="thumbnav">&lt; GIF
&gt;</a></td>
<td><a href="<?php print $weed; ?>?filex=png" class="thumbnav">&lt; PNG
&gt;</a></td>
</tr>
</table>

<div align="center" class="gap5">&nbsp;</div>

<?php

$batman=0;

$joker=opendir($dir);
while (false!==($boywonder=readdir($joker)))
{
$files[]=$boywonder;
$batman=$batman+1;
}



$temp=0;
while ($temp<$batman)
{
$demo=$files[$temp];

$riddler=strlen($demo);
$penguin=substr($demo,$riddler-4,4);
$catwoman=substr($demo,$riddler-10,10);

$img_name="$dir" . "/" . "$demo";
$thumb_name=str_replace($ext,$thumbext,$img_name);

if ($penguin==$ext && $catwoman<>$thumbext)
{

$pass=1;
$filename=$thumb_name;
if (!file_exists($filename)) {$pass=0;}

if ($pass==0)
{
$max_width=150; $max_height=80;
$size=GetImageSize($img_name);
$width_ratio=($size[0] / $max_width); $height_ratio=($size[1] /
$max_height);
if ($width_ratio>=$height_ratio) {$ratio=$width_ratio;} else {$ratio=
$height_ratio;}
$new_width=($size[0] / $ratio); $new_height=($size[1] / $ratio);
if ($ext==".jpg") {$src_img=ImageCreateFromJPEG($img_name);}
if ($ext==".gif") {$src_img=ImageCreateFromGIF($img_name);}
if ($ext==".png") {$src_img=ImageCreateFromPNG($img_name);}
$thumb=ImageCreateTrueColor($new_width,$new_height );
ImageCopyResampled($thumb,$src_img,0,0,0,0,($new_w idth-1),($new_height-
1),$size[0],$size[1]);
ImageJPEG($thumb,$thumb_name,100);
ImageDestroy($src_img);
ImageDestroy($thumb);
}

}

$temp=$temp+1;
}



$homer=0;

$joker=opendir($dir);
while (false!==($boywonder=readdir($joker)))
{
$marge[]=$boywonder;
$homer=$homer+1;
}

$lisa=0;

$temp=0;
while ($temp<$homer)
{
$demo=$marge[$temp];

$riddler=strlen($demo);
$penguin=substr($demo,$riddler-4,4);
$catwoman=substr($demo,$riddler-10,10);

if ($catwoman==$thumbext)
{
$thumb_name="$dir" . "/" . "$demo";
$img_name=str_replace($thumbext,$ext,$thumb_name);
$millhouse[$lisa]=$thumb_name;
$diamondjoe[$lisa]=$img_name;
$lisa=$lisa+1;
}

$temp=$temp+1;
}

?>

<?php

print "<table border=0 cellspacing=1 cellpadding=0 align=center>";

$loopy=0;

while ($loopy<$lisa)
{

print "<tr valign=top>";

$tempxx=0;
while ($tempxx<$columns)
{

if ($loopy<$lisa)
{

$passimage=1;
$filename=$diamondjoe[$loopy];
if (!file_exists($filename)) {$passimage=0;}

if ($passimage==0)
{
print "<td class=box>";
print "$filename";
print "<br>";
print "<span class=rrb>FILE NOT FOUND</span>";
print "<br><br>";
print "<span class=mma>DELETE THE FOLLOWING FILE</span>";
print "<br>";
print "<span class=nnb>$millhouse[$loopy]</span>";
print "<br>";
print "<span class=mma>TO PREVENT THIS ERROR FROM HAPPENING</span>";
print "</td>";
}

if ($passimage==1)
{
$moe=filesize($diamondjoe[$loopy]);
$ralph=$moe;
$wiggum=strlen($moe);
if ($ralph>999) {$ralph=substr($ralph,0,$wiggum-3);} else {$ralph="?";}
$barney="$ralph" . "k";
$apu=GetImageSize($diamondjoe[$loopy]);
$size=GetImageSize($millhouse[$loopy]);
$duffbeer=$loopy+1;
print "<td class=box>";
print "<div align=left class=bar><span class=nna>($duffbeer)</span>
<span class=bba>$apu[0] x $apu[1]</span<span class=mma>$barney</span>
</div>";
print "";
print "<div align=center class=gap3>&nbsp</div>";
print "<a href=$diamondjoe[$loopy]><img src=$millhouse[$loopy] width=
$size[0] height=$size[1] border=0></a><br>";
print "</td>";
}

}

$tempxx=$tempxx+1;
$loopy=$loopy+1;
}

print "</tr>";

}

print "</table>";

?>

</body>
</html>




hakan.magnusson@gmail.com
Guest
 
Posts: n/a
#2: Oct 30 '06

re: Create thumbnails with clickable links XYZ


This must be the worst naming of variables and functions I've seen in a
long time. I would absolutely refuse to work with this code if I found
it in a commercial project. Lets hope nobody every points to this post,
shall we.

On Oct 30, 1:59 am, Krustov <m...@privacy.netwrote:
Quote:
The question of how to create thumbnails with clickable links gets asked
on this newsgroup every so often - like clock work .
>
Just really posing this script here for google to archive it & so users
can be pointed to it in the future via a link to google groups .
>
<html>
<head>
<title>thumbnails.php</title>
</head>
>
<style type="text/css">
>
body {margin-bottom : 0px;margin-left : 0px; margin-right : 0px;
margin-top : 0px;}
>
A:link {text-decoration: none;}
A:visited {text-decoration: none;}
A:active {text-decoration: none;}
A:hover {text-decoration : underline;}
>
.backy{background-color: #FFEEFF;}
>
.gap1{font-size: 1px;}
.gap2{font-size: 2px;}
.gap3{font-size: 3px;}
.gap4{font-size: 4px;}
.gap5{font-size: 5px;}
.gap6{font-size: 6px;}
.gap7{font-size: 7px;}
.gap8{font-size: 8px;}
.gap9{font-size: 9px;}
>
.tap
{
color : Black; background-color: #F9FBFB;
font-size : 20pt; font-family : Arial;
padding-left: 22px; padding-right: 22px; padding-top: 3px; padding-
bottom: 3px;
border: 1px solid #CFD1F1;
>
}.box
{
background-color: #FFEFFF;
padding-left: 2px; padding-right: 2px; padding-top: 2px; padding-bottom:
2px;
border: 1px solid #FEDAFE;
>
}.bar
{
background-color: #F5DDFF;
padding-left: 5px; padding-right: 5px; padding-top: 0px; padding-bottom:
3px;
border: 1px solid #DADBD1;
>
}.thumbnav
{
color: #000000; background-color: #F4DEDE;
font-size: 10pt; font-family: Arial; text-align: center;
padding-left: 9px; padding-right: 9px; padding-top: 4px; padding-bottom:
4px;
>
}.thumbnav:hover
{
text-decoration: none;
color: #000000; background: #FFFFC0;
>
}.mma{color : Maroon; font-size : 8pt;font-family : Arial;}
.mmb{color : Maroon; font-size : 10pt;font-family : Arial;}
.mmc{color : Maroon; font-size : 12pt;font-family : Arial;}
.mmd{color : Maroon; font-size : 14pt;font-family : Arial;}
>
.bba{color : Black; font-size : 8pt;font-family : Arial;}
.bbb{color : black; font-size : 10pt;font-family : Arial;}
.bbc{color : Black; font-size : 12pt;font-family : Arial;}
.bbd{color : Black; font-size : 14pt;font-family : Arial;}
>
.nna{color : Navy; font-size : 8pt;font-family : Arial;}
.nnb{color : Navy; font-size : 10pt;font-family : Arial;}
.nnc{color : Navy; font-size : 12pt;font-family : Arial;}
.nnd{color : Navy; font-size : 14pt;font-family : Arial;}
>
.rra{color : Red;font-size : 8pt;font-family : Arial;}
.rrb{color : Red;font-size : 10pt;font-family : Arial;}
.rrc{color : Red;font-size : 12pt;font-family : Arial;}
.rrd{color : Red;font-size : 14pt;font-family : Arial;}
>
</style>
>
<body class="backy">
>
<?php
>
$weed=basename($_SERVER['PHP_SELF']);
>
$dir="test/images"; $columns=6;
>
$ext=".jpg";
>
# .jpg .gif .png , You can use any of these 3 image extensions , But not
more than one at a time .
>
$what=$_REQUEST['filex']; $what=strtolower($what);
>
if ($what<>"")
{
if ($what=="jpg") {$ext=".jpg";}
if ($what=="gif") {$ext=".gif";}
if ($what=="png") {$ext=".png";}
>
}$thumbext="_thumb" . "$ext";
>
$whatupper=str_replace(".","",$ext); $whatupper=strtoupper($whatupper);
>
?>
>
<div align="center" class="gap9">&nbsp;</div>
>
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="tap">THUMBNAILS - <?php print $whatupper; ?></td>
</tr>
</table>
>
<div align="center" class="gap5">&nbsp;</div>
>
<table border="0" cellspacing="5" cellpadding="0" align="center">
<tr>
<td><a href="<?php print $weed; ?>?filex=jpg" class="thumbnav">&lt; JPG
&gt;</a></td>
<td><a href="<?php print $weed; ?>?filex=gif" class="thumbnav">&lt; GIF
&gt;</a></td>
<td><a href="<?php print $weed; ?>?filex=png" class="thumbnav">&lt; PNG
&gt;</a></td>
</tr>
</table>
>
<div align="center" class="gap5">&nbsp;</div>
>
<?php
>
$batman=0;
>
$joker=opendir($dir);
while (false!==($boywonder=readdir($joker)))
{
$files[]=$boywonder;
$batman=$batman+1;
>
}$temp=0;
while ($temp<$batman)
{
$demo=$files[$temp];
>
$riddler=strlen($demo);
$penguin=substr($demo,$riddler-4,4);
$catwoman=substr($demo,$riddler-10,10);
>
$img_name="$dir" . "/" . "$demo";
$thumb_name=str_replace($ext,$thumbext,$img_name);
>
if ($penguin==$ext && $catwoman<>$thumbext)
{
>
$pass=1;
$filename=$thumb_name;
if (!file_exists($filename)) {$pass=0;}
>
if ($pass==0)
{
$max_width=150; $max_height=80;
$size=GetImageSize($img_name);
$width_ratio=($size[0] / $max_width); $height_ratio=($size[1] /
$max_height);
if ($width_ratio>=$height_ratio) {$ratio=$width_ratio;} else {$ratio=
$height_ratio;}
$new_width=($size[0] / $ratio); $new_height=($size[1] / $ratio);
if ($ext==".jpg") {$src_img=ImageCreateFromJPEG($img_name);}
if ($ext==".gif") {$src_img=ImageCreateFromGIF($img_name);}
if ($ext==".png") {$src_img=ImageCreateFromPNG($img_name);}
$thumb=ImageCreateTrueColor($new_width,$new_height );
ImageCopyResampled($thumb,$src_img,0,0,0,0,($new_w idth-1),($new_height-
1),$size[0],$size[1]);
ImageJPEG($thumb,$thumb_name,100);
ImageDestroy($src_img);
ImageDestroy($thumb);
>
}
}$temp=$temp+1;
>
}$homer=0;
>
$joker=opendir($dir);
while (false!==($boywonder=readdir($joker)))
{
$marge[]=$boywonder;
$homer=$homer+1;
>
}$lisa=0;
>
$temp=0;
while ($temp<$homer)
{
$demo=$marge[$temp];
>
$riddler=strlen($demo);
$penguin=substr($demo,$riddler-4,4);
$catwoman=substr($demo,$riddler-10,10);
>
if ($catwoman==$thumbext)
{
$thumb_name="$dir" . "/" . "$demo";
$img_name=str_replace($thumbext,$ext,$thumb_name);
$millhouse[$lisa]=$thumb_name;
$diamondjoe[$lisa]=$img_name;
$lisa=$lisa+1;
>
}$temp=$temp+1;
>
}?>
>
<?php
>
print "<table border=0 cellspacing=1 cellpadding=0 align=center>";
>
$loopy=0;
>
while ($loopy<$lisa)
{
>
print "<tr valign=top>";
>
$tempxx=0;
while ($tempxx<$columns)
{
>
if ($loopy<$lisa)
{
>
$passimage=1;
$filename=$diamondjoe[$loopy];
if (!file_exists($filename)) {$passimage=0;}
>
if ($passimage==0)
{
print "<td class=box>";
print "$filename";
print "<br>";
print "<span class=rrb>FILE NOT FOUND</span>";
print "<br><br>";
print "<span class=mma>DELETE THE FOLLOWING FILE</span>";
print "<br>";
print "<span class=nnb>$millhouse[$loopy]</span>";
print "<br>";
print "<span class=mma>TO PREVENT THIS ERROR FROM HAPPENING</span>";
print "</td>";
>
}if ($passimage==1)
{
$moe=filesize($diamondjoe[$loopy]);
$ralph=$moe;
$wiggum=strlen($moe);
if ($ralph>999) {$ralph=substr($ralph,0,$wiggum-3);} else {$ralph="?";}
$barney="$ralph" . "k";
$apu=GetImageSize($diamondjoe[$loopy]);
$size=GetImageSize($millhouse[$loopy]);
$duffbeer=$loopy+1;
print "<td class=box>";
print "<div align=left class=bar><span class=nna>($duffbeer)</span>
<span class=bba>$apu[0] x $apu[1]</span<span class=mma>$barney</span>
</div>";
print "";
print "<div align=center class=gap3>&nbsp</div>";
print "<a href=$diamondjoe[$loopy]><img src=$millhouse[$loopy] width=
$size[0] height=$size[1] border=0></a><br>";
print "</td>";
>
}
}$tempxx=$tempxx+1;
$loopy=$loopy+1;
>
}print "</tr>";
>
}print "</table>";
>
?>
>
</body>
</html>
Krustov
Guest
 
Posts: n/a
#3: Oct 30 '06

re: Create thumbnails with clickable links XYZ


<comp.lang.php>
<hakan.magnusson@gmail.com>
<30 Oct 2006 06:58:33 -0800>
<1162220312.874847.142150@m7g2000cwm.googlegroups. com>
Quote:
This must be the worst naming of variables and functions I've seen in a
long time. I would absolutely refuse to work with this code if I found
it in a commercial project. Lets hope nobody every points to this post,
shall we.
>
Tickled yer fancy did it :-)


--
www.phpchatroom.co.uk
Closed Thread