PHP image gallery - NO THUMBNAILS

DexterDexter Vancouver, BC Canada
edited March 2006 in Internet & Media
On the site I am an admin at, we have a directory full of small images. These are used similar to smilies, except they are country flags, signal flags, and military medals. Having gotten tired of being constantly asked what flags / medals we have, I would like to have a simple gallery for them.

I have done some searching, and found probably hundreds of gallery generators. My problem is that they are all designed for large images, and include automatic thumbnail creation. Since most of my images are small (think smily sized or smaller) I don't need thumbnails. I found a great script that I like, but even that does thumbs, min size 30 pix, which ends up enlarging all my images and making them look ugly.

Does anyone know of a script to display just the images with their name underneath them (we need the name so people know what to type in the BBcode tag, and preferably the name only, no ".gif" extension.) WITHOUT THUMBNAILS? I don't need any of the other things normally found in gallery scripts - no uploads, downloads, comments, nada. This is just a listing of what is in the directory, the image, name and nothing else. I would prefer one that lets me control how many images per page (the one I have been monkeying with gives me options for images per page and number of columns, etc.)

Then ideally I need to be able to embed this page into one of my site's standard looking pages.

Thanks in advance.

Dexter...

Comments

  • MiracleManSMiracleManS Chambersburg, PA Icrontian
    edited February 2006
    I actually wrote one in ASP a while back(used an access database though, I think)...I could always translate it to PHP if you wanted.
  • DexterDexter Vancouver, BC Canada
    edited February 2006
    If it is not too much trouble...yes please :)

    Does not have to be complex. I can PM you a link to what I am looking to do....


    Dexter...
  • ShortyShorty Manchester, UK Icrontian
    edited February 2006
    [php]
    <?php
    // Set base requirements
    $ImgDirectory = './forum/images/smilies';
    $NumColumns = '3';
    $ImgPerPage = '10';

    // Feed into array
    $files = array();
    $listings = opendir($ImgDirectory);
    while (false !== ($filename = readdir($listings)))
    {
    if ($filename != "." && $filename != "..")
    {
    $files[] = $filename;
    }
    }
    closedir($listings);

    // Calculate number of pages..
    $TotalNumImages = count($files);
    $TotalPages = ceil($TotalNumImages/$ImgPerPage);

    //Decide Page number
    if (!isset($_GET))
    {
    $p = 1;
    $LimitValue = 0;
    }
    else
    {
    $p = $_GET;
    $LimitValue = $p * $ImgPerPage - ($ImgPerPage);
    }

    // Make some HTML
    $html = '<table border="1" width="100%">';

    // Define TD size
    $TdWidth = 100/$NumColumns;

    // Set iteration vars
    $stop = $LimitValue + $ImgPerPage;
    $cc = 1;
    // Iterate images
    while($LimitValue != $stop)
    {
    $fn = explode('.', $files[$LimitValue]);
    // Make a column
    switch($cc)
    {
    case 1:
    $html .= '<tr>';
    $html .= '<td align="center" width="'.$TdWidth.'%">
    <img src="'.$ImgDirectory.'/'.$fn[0].'.'.$fn[1].'"><br />'.$fn[0].'
    </td>';
    $cc++;
    break;

    case $NumColumns:
    $html .= '<td align="center" width="'.$TdWidth.'%">
    <img src="'.$ImgDirectory.'/'.$fn[0].'.'.$fn[1].'"><br />'.$fn[0].'
    </td>';
    $html .= '</tr>';
    $cc = 1;
    break;

    default:
    $html .= '<td align="center" width="'.$TdWidth.'%">
    <img src="'.$ImgDirectory.'/'.$fn[0].'.'.$fn[1].'"><br />'.$fn[0].'
    </td>';
    $cc++;
    break;
    }
    $LimitValue++;
    }

    // Check for empty cells
    if($cc != $NumColumns)
    {
    for($i = $cc; $i <= $NumColumns; $i++)
    {
    $html .= '<td align="center" width="'.$TdWidth.'%">
     
    </td>';
    }
    $html .= '</tr>';
    }
    $html .= '</table><br />';

    //Generate PREV navs
    if ($p > 1)
    {
    $pagenum = $p - 1;
    $url = $_SERVER.'?p='.$pagenum;
    $html .= '<a href="'.$url.'">Prev</a> | ';
    }
    //Page Numbers
    if ($TotalPages > 1)
    {
    for($i = 1; $i <= $TotalPages; $i++)
    {
    if($i == $p)
    {
    $html .= "<b>".$_GET."</b> ";
    }
    else
    {
    $url = $_SERVER.'?p='.$i;
    $html .= '<a href="'.$url.'">'.$i.'</a> ';
    }
    }
    }
    //Generate NEXT nav
    if ($p < $TotalPages)
    {
    $pagenum = $p + 1;
    $url = $_SERVER.'?p='.$pagenum;
    $html .= ' | <a href="'.$url.'">Next</a>';
    }

    echo $html;
    ?>
    [/php]

    It's simple and needs tweaking.. but It's nearly 12am here and I have a 7am start. Im sure you can figure out the rest, the core is there. Not bad for 15 minutes work.. and it does work.. :) Edit the following lines:

    [php]
    // Set base requirements
    $ImgDirectory = './forum/images/smilies';
    $NumColumns = '3';
    $ImgPerPage = '10';
    [/php]

    To reflect the values you want and then tinker with the PHP as you go along :)
  • DexterDexter Vancouver, BC Canada
    edited February 2006
    :respect::respect::respect::respect::respect:

    I will try this out this evening and let you know how it looks.

    I owe you yet again, mate!

    Dexter...
  • DexterDexter Vancouver, BC Canada
    edited March 2006
    Shorty, (or anyone),

    I have two problems with that code:

    - it sorts by file date, not alphabetically. How would I get that to sort alphabetically

    - the code inserts missing image placeholders to fill the table size. IE, say I have it set for 8 columns, max 64 images per page. My third page maybe has 37 images. I get 3 broken image placeholders filling out the fifth row.

    Thoughts?

    Dexter...
  • ShortyShorty Manchester, UK Icrontian
    edited March 2006
    I did get your PM, Im totally bogged down with work.. which is why I've had no time to reply :(

    I admit that script is a hack job, but it was thrown together in 15 minutes. If I can find some time over the next few days.. Il tidy it up a little :)
  • DexterDexter Vancouver, BC Canada
    edited March 2006
    No problem mate, I appreciate whatever you can do. :)

    Dexter...
  • MiracleManSMiracleManS Chambersburg, PA Icrontian
    edited March 2006
    Dexter wrote:
    Shorty, (or anyone),

    I have two problems with that code:

    - it sorts by file date, not alphabetically. How would I get that to sort alphabetically

    - the code inserts missing image placeholders to fill the table size. IE, say I have it set for 8 columns, max 64 images per page. My third page maybe has 37 images. I get 3 broken image placeholders filling out the fifth row.

    Thoughts?

    Dexter...

    I saw Shorty hadn't replied, and I know he's busy, so I tweaked it up for him. If he's already done it, that's fine, but this should do exactly what you want it to do now.

    [PHP]<?php
    // Set base requirements
    $ImgDirectory = './outlookfolder';
    $NumColumns = '1';
    $ImgPerPage = '2';

    // Feed into array
    $files = array();
    $listings = opendir($ImgDirectory);
    while (false !== ($filename = readdir($listings)))
    {
    if ($filename != "." && $filename != "..")
    {
    $files[] = $filename;
    }
    }
    closedir($listings);

    sort($files);

    // Calculate number of pages..
    $TotalNumImages = count($files);
    $TotalPages = ceil($TotalNumImages/$ImgPerPage);

    //Decide Page number
    if (!isset($_GET))
    {
    $p = 1;
    $LimitValue = 0;
    }
    else
    {
    $p = $_GET;
    $LimitValue = $p * $ImgPerPage - ($ImgPerPage);
    }

    // Make some HTML
    $html = '<table border="1" width="100%">';

    // Define TD size
    $TdWidth = 100/$NumColumns;

    // Set iteration vars
    $stop = $LimitValue + $ImgPerPage;
    $cc = 1;
    // Iterate images
    while($LimitValue != $stop)
    {
    $fn = explode('.', $files[$LimitValue]);
    if($cc==1)
    {
    $html .= '<tr>';
    $html .= '<td align="center" width="'.$TdWidth.'%">
    <img src="'.$ImgDirectory.'/'.$fn[0].'.'.$fn[1].'">'.$fn[0].'
    </td>';
    $cc++;
    }
    elseif(($p*$ImgPerPage)<=$TotalNumImages)
    {
    $html .= '<td align="center" width="'.$TdWidth.'%">
    <img src="'.$ImgDirectory.'/'.$fn[0].'.'.$fn[1].'">'.$fn[0].'
    </td>';
    $html .= '</tr>';
    $cc = 1;
    }
    else
    {
    $html .= '</tr>';
    }

    $LimitValue++;
    }

    $html .= '</table>';
    //Generate PREV navs
    if ($p > 1)
    {
    $pagenum = $p - 1;
    $url = $_SERVER.'?p='.$pagenum;
    $html .= '<a href="'.$url.'">Prev</a> | ';
    }
    //Page Numbers
    if ($TotalPages > 1)
    {
    for($i = 1; $i <= $TotalPages; $i++)
    {
    if($i == $p)
    {
    $html .= "<b>".$_GET."</b> ";
    }
    else
    {
    $url = $_SERVER.'?p='.$i;
    $html .= '<a href="'.$url.'">'.$i.'</a> ';
    }
    }
    }
    //Generate NEXT nav
    if ($p < $TotalPages)
    {
    $pagenum = $p + 1;
    $url = $_SERVER.'?p='.$pagenum;
    $html .= ' | <a href="'.$url.'">Next</a>';
    }

    echo $html;
    ?>
    [/PHP]
  • DexterDexter Vancouver, BC Canada
    edited March 2006
    Thanks MMS! I will give that a try as soon as I get a chance and let you know how it works. I greatly appreciate your time and effort.

    Cheers,

    Dexter...
Sign In or Register to comment.