473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Yet Another Thumbnail-Slideshow Program Quick and Dirty

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 "<styleA { 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><styleA { 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

Dec 22 '06 #1
1 2119
NC
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

Dec 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil Powell | last post by:
PHP 4.3.2 with --enable-exif I have the following class: <?php class ThumbGenerator extends MethodGeneratorForActionPerformer { function ThumbGenerator() { // CONSTRUCTOR
0
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web...
7
by: Chris Perry | last post by:
How do you create a thumbnail constrained to a box, without distorting and but making where it doesn't fill the box transparent. I'm two thirds there : Size fitImageSize =...
6
by: Trint Smith | last post by:
How can I show image thumbnail?? thanks, Trint ..Net programmer trintsmith@hotmail.com *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get...
11
by: Jane | last post by:
Hi, I need some help (php rookie) to build a thumbnail page using php. I'v a mysql database containing links to the original image files. No thumbnails created so far. It would be nice when...
4
by: karsting | last post by:
I am using this css. I have a link from the thumbnail to another page, but need to go to the same link on the pop-up image. IN STYLES } .thumbnail{ position: relative; z-index: 0;
1
by: dodgeyb | last post by:
Hi there, Trying to allow client to upload image, thumbnail it, and save it into sql table image field. Code compiles & runs but image cannot be retrieved. any clues what I'm doing wrong pls ! ...
15
tlhintoq
by: tlhintoq | last post by:
I'd like to think I can work out most issues, but this one is kicking my butt. What's worse, is that I know I can't be the first guy to want to add a thumbnail to jpg that doesn't already have one. ...
2
by: Gunasegar | last post by:
Greeting to all am trying to create thumbnail from image stored in mysql database.. this is the coding am using to create the thumbnail... this works like charm.. but the problem is that the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.