Here are some scripts I have written to dynamically build a HTML table of
thumbnails & insert it as an OBJECT element in the page from which it is
called.
The top-level page contains JavaScript to create the OBJECT element:
<script LANGUAGE="JavaScript1.2">
OutStr = '<object type="text/html" data="BuildThumbnailGrid.php?win_width='
+ GetWinWidth() + '&img_width=100&border_width=0&cell_space=40" width="100%"
height="100%" border=0>If you are reading this your browser doesn’t
support Object element...oprostite.'
document.write(OutStr);
document.write('</object>');
</script>
You can use this JS function to find out how wide your browser window is,
otherwise just enter no. of pixels:
<script LANGUAGE="JavaScript1.2">
function GetWinWidth()
{
if (navigator.appName == 'Netscape' && document.layers != null)
{
return WinWidth = window.innerWidth;
}
if (document.all != null)
{
return WinWidth = document.body.clientWidth;
}
}
</script>
The OBJECT element calls the BuildThumbnailGrid.php script, which in turn
finds all the *.JPG files in the current directory (or whichever you
specify) and calls MakeThumbnail.php to make a thumbnail on the fly.
File BuildThumbnailGrid.php:
-----------------------------
<?php
// Pass available window width as win_width using HTTP GET method
// Pass thumbnail width as img_width HTTP GET method
// Pass table border width as border_width using HTTP GET method
// Pass cell padding as cell_pad using HTTP GET method
// Pass cell spacing width as cell_space using HTTP GET method
$win_width = $_GET["win_width"];
$img_width = $_GET["img_width"];
$border_width = $_GET["border_width"];
$cell_pad = $_GET["cell_pad"];
$cell_space = $_GET["cell_space"];
// Calculate no. of columns that will fit window
$num_cols = floor(($win_width - $cell_space)/($img_width + $cell_space)) -
1;
$curr_col = 0; //Set column counter to zero
echo '<table border=' . $border_width . ' cellspacing=' . $cell_space .
'>';
foreach (glob("*.JPG") as $filename) /* Needs PHP 4 >= 4.3.0, PHP 5 to
work. Use readdir() to build array otherwise. */
{
if ($curr_col == 0)
echo '<tr>';
echo '<td>';
echo '<a href="' . $filename . '">';
echo '<img src="MakeThumbnail.php?in_file=' . $filename . '&in_width=' .
$img_width . '">';
echo '</a>';
echo '</td>';
if ($curr_col < $num_cols)
$curr_col += 1;
else
{
echo '</tr>';
$curr_col = 0;
}
}
if ($curr_col < $num_cols)
echo '</tr>';
echo '</table>';
?>
File MakeThumbnail.php:
-------------------------
<?php
// Pass arguments with HTTP GET method
// Pass $filename as in_file
// Pass $new_width as in_width
$filename = $_GET["in_file"];
if (isset($_GET["in_width"]))
$new_width = $_GET["in_width"];
else
$new_width = 120;
// Set content type
header('Content-type: image/jpeg');
// Get image dimensions & resize
list($width, $height) = getimagesize($filename);
$aspect_ratio = $height / $width;
$new_height = $new_width * $aspect_ratio;
// Resample
$output_image = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($output_image, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);
// Output image
imagejpeg($output_image, null, 100);
?>
"Johan" <me@knoware.nl> wrote in message
news:10*************@corp.supernews.com...
Hi,
Where to find a php script to upload jpg files and make thumbnails of the
jpg files ?
Johan