For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > December 2006 > Yet Another Thumbnail-Slideshow Program Quick and Dirty









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Yet Another Thumbnail-Slideshow Program Quick and Dirty
John Henckel

2006-12-22, 6:59 pm

This is the simplest, quickest, dirtiest, leanest, meanest,
thumbnail/slideshow image viewer PHP script I have ever seen.

Enjoy, John



--------- CUT HERE -------------------

<?php
/*
Will generate a pages width of thumbnailed GIF's and JPG's
from a secified directory. Will work in a directory with other files in it
with no problems.

Generated: 24/3/03 by Author: Rock
Greatly modified and enhanced: John Henckel 2004-2006, formulus.com

How to use it. Change the $self below. Put this file on your web host.
Open it in the browser. You should see links to each directory (including
the parent) and thumbnails for each image. If you don't, too bad.
Try adjusting the permission bits on the directory.

Note, this is not an example of good programming,
it is an example of the iterative hacking methodology.

PUBLIC DOMAIN - NOT COPYRIGHTED - DO WHATEVER YOU WANT WITH IT
*/

// The location of thumb.php on your host goes here...

$self = "/mypics/thumb.php"

// Set variables
$default_dir = "."; // Relative to current location
$QUERY_STRING = $_SERVER['QUERY_STRING'];

$t_width = 100; // Thumbnail width
$t_height = 100; // Thumbnail height

if (isset($_REQUEST['id']))
{
$id = $_REQUEST['id'];
if (isset($_REQUEST['dir'])) $default_dir = $_REQUEST['dir'];
// slide show
$n = 0;
$dp = opendir($default_dir);
while($file = readdir($dp)){
if(stristr($file,".jpg"))
{
++$n;
if ($n == $id) $img = "<img src=\"$default_dir/$file\">";
if ($n == $id + 1) $nxt = "<img src=\"$default_dir/$file\" width=100
align=top>";

// prefetch the next image, for smoother transitions
}
}
closedir($dp);

if (isset($_REQUEST['t'])) $t = $_REQUEST['t']; else $t = 7; //
time per slide

$c = $n;
if ($n > $id) $n = $id + 1; else $n = 1; // next id
echo "<html><head>";
if ($t > 0)
echo "<meta http-equiv=\"refresh\"
content=\"$t;url=?dir=$default_dir&t=$t&id=$n\"/>\n";
echo "<style> A { color:white; } </style></head>";
echo "<body bgcolor=black><font face=arial color=white><b>";
echo "<a href=?$default_dir>all</a> - ";
if ($t > 0)
echo "<a href=?dir=$default_dir&t=0&id=$id>pause</a> - ";
else
echo "<a href=?dir=$default_dir&t=3&id=$n>play</a> - ";
if ($id > 0)
echo "<a href=?dir=$default_dir&t=$t&id=".($id-1).">prev</a> - ";
echo "<a href=?dir=$default_dir&t=$t&id=$n>next</a> - ";
if ($t > 0) echo " delay=$t - ";
if ($t > 1) {
echo "<a href=?dir=$default_dir&t=".($t-1)."&id=$n>faster</a> - ";
echo "<a href=?dir=$default_dir&t=".($t+1)."&id=$id>slower</a> - ";
}
echo "($id of $c)";
echo "<br>$img $nxt</body></html>";
}
// get and display jpeg images
else if(stristr($QUERY_STRING,".jpg")){
header("Content-type: image/jpeg");
$f = str_replace("%20"," ",$QUERY_STRING);
$srcimage = imagecreatefromjpeg($f);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
$t_width = $width * $t_height / $height; /* preserve ratio */
$destimage = imagecreate($t_width,$t_height);
imagecopyresized
($destimage,$srcimage,0,0,0,0,$t_width,$
t_height,$width,$height);
ImageJPEG($destimage);
ImageDestroy($destimage);
}
else if (stristr($QUERY_STRING,"test"))
{
$f = str_replace("%20"," ",$QUERY_STRING);
echo "---$QUERY_STRING---$f---";
}
else
{
if ($QUERY_STRING) $default_dir = $QUERY_STRING;
echo "<head><style> A { color:white; } </style></head>";
echo "<body bgcolor=black><font face=arial color=white>";
// Directory Scan
if(!($dp = opendir($default_dir))) die("Cannot open $dir");
// Place images into image tag
$par = preg_replace('/\\/[^\\/]*/','',$default_dir);
if ($par == $default_dir) $par .='/..';
echo "<a href=\"$self?$par\">...parent...</a><br> ";
while($file = readdir($dp)){
if (is_dir($file) && $file{0} != '.')
echo "<a href=\"$self?$default_dir/$file\">$file</a> ";
}
closedir($dp);
echo "<hr><a href=?dir=$default_dir&id=1><b>-- click here for slide show
--</b></a><br>";
$dp = opendir($default_dir);
$id = 0;
while($file = readdir($dp)){
// echo "<p>$file ";
if( stristr($file,".jpg"))
{
$id++;
echo "<a href=\"$self?dir=$default_dir&t=0&id=$id\"><img
src=\"$self?$default_dir/$file\" border=0></a>\r\n";
}
}

closedir($dp);

}
?>


---------- CUT HERE ---------------

--
Posted via a free Usenet account from http://www.teranews.com

NC

2006-12-24, 3:59 am

John Henckel wrote:
>
> This is the simplest, quickest, dirtiest, leanest, meanest,
> thumbnail/slideshow image viewer PHP script I have ever seen.


OK, this may be, but why do this:

> // The location of thumb.php on your host goes here...
> $self = "/mypics/thumb.php"


when you can write:

$self = $_SERVER['PHP_SELF'];

???

Cheers,
NC

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com