Yet Another Thumbnail-Slideshow Program Quick and Dirty

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Henckel

    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($_REQUES T['id']))
    {
    $id = $_REQUEST['id'];
    if (isset($_REQUES T['dir'])) $default_dir = $_REQUEST['dir'];
    // slide show
    $n = 0;
    $dp = opendir($defaul t_dir);
    while($file = readdir($dp)){
    if(stristr($fil e,".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($_REQUES T['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><hea d>";
    if ($t 0)
    echo "<meta http-equiv=\"refresh \"
    content=\"$t;ur l=?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=$defa ult_dir&t=0&id= $id>pause</a- ";
    else
    echo "<a href=?dir=$defa ult_dir&t=3&id= $n>play</a- ";
    if ($id 0)
    echo "<a href=?dir=$defa ult_dir&t=$t&id =".($id-1).">prev</a- ";
    echo "<a href=?dir=$defa ult_dir&t=$t&id =$n>next</a- ";
    if ($t 0) echo " delay=$t - ";
    if ($t 1) {
    echo "<a href=?dir=$defa ult_dir&t=".($t-1)."&id=$n>fast er</a- ";
    echo "<a href=?dir=$defa ult_dir&t=".($t +1)."&id=$id>sl ower</a- ";
    }
    echo "($id of $c)";
    echo "<br>$img $nxt</body></html>";
    }
    // get and display jpeg images
    else if(stristr($QUE RY_STRING,".jpg ")){
    header("Content-type: image/jpeg");
    $f = str_replace("%2 0"," ",$QUERY_STRING );
    $srcimage = imagecreatefrom jpeg($f);
    $width = imageSX($srcima ge);
    $height = imageSY($srcima ge);
    $t_width = $width * $t_height / $height; /* preserve ratio */
    $destimage = imagecreate($t_ width,$t_height );
    imagecopyresize d
    ($destimage,$sr cimage,0,0,0,0, $t_width,$t_hei ght,$width,$hei ght);
    ImageJPEG($dest image);
    ImageDestroy($d estimage);
    }
    else if (stristr($QUERY _STRING,"test") )
    {
    $f = str_replace("%2 0"," ",$QUERY_STRING );
    echo "---$QUERY_STRING---$f---";
    }
    else
    {
    if ($QUERY_STRING) $default_dir = $QUERY_STRING;
    echo "<head><sty leA { color:white; } </style></head>";
    echo "<body bgcolor=black>< font face=arial color=white>";
    // Directory Scan
    if(!($dp = opendir($defaul t_dir))) die("Cannot open $dir");
    // Place images into image tag
    $par = preg_replace('/\\/[^\\/]*/','',$default_d ir);
    if ($par == $default_dir) $par .='/..';
    echo "<a href=\"$self?$p ar\">...parent. ..</a><br";
    while($file = readdir($dp)){
    if (is_dir($file) && $file{0} != '.')
    echo "<a href=\"$self?$d efault_dir/$file\">$file</a";
    }
    closedir($dp);
    echo "<hr><a href=?dir=$defa ult_dir&id=1><b >-- click here for slide show
    --</b></a><br>";
    $dp = opendir($defaul t_dir);
    $id = 0;
    while($file = readdir($dp)){
    // echo "<p>$file ";
    if( stristr($file," .jpg"))
    {
    $id++;
    echo "<a href=\"$self?di r=$default_dir& t=0&id=$id\"><i mg
    src=\"$self?$de fault_dir/$file\" border=0></a>\r\n";
    }
    }

    closedir($dp);

    }
    ?>


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

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

  • NC

    #2
    Re: Yet Another Thumbnail-Slideshow Program Quick and Dirty

    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

    Comment

    Working...