Web Analytics Made Easy -
StatCounter Help with image script - CodingForum

Announcement

Collapse
No announcement yet.

Help with image script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with image script

    I have found a image script that will automatically thumbnail for me but shows them all on one page. The problem I have is that my my image folders can contain quite a few images and I was wondering if anybody here could help me so that the script only shows 27 images per page. I have tried to contact the original writer of the script and haven't heard back from the person, I would greatly appreciate if somebody here could help me out.

    Here is the script:

    <?php
    // TStarGallery 1.0 engine
    // With basic PHP knowledge you can understand what's happening here.
    // Don't blame me for writing non-perfect code for I do not care.
    // If there is an error or something, mail me at tstar @ taillandier.de


    // Read the current directory, throw out non-jpg/gif/png + thumbfiles
    // --------------------------------------------------------------------
    $dirfiles = array();

    $handle=opendir('.');
    while ($file = readdir($handle)) {
    if
    ((
    strtolower(strrchr($file, '.')) == ".jpg" OR
    strtolower(strrchr($file, '.')) == ".jpeg" OR
    strtolower(strrchr($file, '.')) == ".png" OR
    strtolower(strrchr($file, '.')) == ".gif"
    )
    &&
    (
    strstr($file, "_t.jpg") == ''
    ))
    {
    array_push($dirfiles, $file);
    }
    }
    sort ($dirfiles);
    closedir($handle);

    // Write the beginning of the basic table for displaying the thumbs.
    // Modify this section to make it fit your own website.
    // -----------------------------------------------------------------
    echo "<table width=\"505\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" id=\"structure\"><tr>";


    // Read the valid filenames from the array, have your way with every single one of them
    // ------------------------------------------------------------------------------------

    foreach($dirfiles as $aktuellesfile)
    {
    // Elements of the filename are cut into pieces
    $dateiendung = strrchr( $aktuellesfile, '.' );
    $dateiname = substr_replace ($aktuellesfile, '', -strlen($dateiendung) );


    // First a routine for creating a thumb
    createthumb ($dateiname, $dateiendung);
    // Now open up a table cell
    echo "<td>";
    // Second a routine for showing a thumb
    showthumb ($dateiname, $dateiendung);
    // Close the table cell
    echo "</td>";
    // And make a linebreak after every 3 thumbs
    if(++$cnt % 3 == 0) echo "</tr>";
    }

    // Finished
    exit;


    // Function to create a thumbnail if it doesn't already exist
    // -----------------------------------------------------------------
    function createthumb ($thumbdateiname, $thumbdateiendung)
    {
    $fullname = $thumbdateiname.$thumbdateiendung;
    $fullthumbname = $thumbdateiname."_t.jpg";

    // If thumb exists,nothing will happen
    if (file_exists($fullthumbname) OR strstr($fullname, "_t.jpg") != '')
    {
    }
    // If thumb doesn't exist,it's created now
    else
    {
    if ((strtolower($thumbdateiendung) == ".jpg") OR (strtolower($thumbdateiendung) == ".jpeg")){
    $src_img = imagecreatefromjpeg($fullname);
    }
    if (strtolower($thumbdateiendung) == ".gif"){
    $src_img = imagecreatefromgif($fullname);
    }
    if (strtolower($thumbdateiendung) == ".png"){
    $src_img = imagecreatefrompng($fullname);
    }

    $origx=imagesx($src_img);
    $origy=imagesy($src_img);

    // Maximum width and height of the thumbnails
    $max_x = 150;
    $max_y = 150;

    // Calc, if thumb has has to be squeezed from width or height
    if($origx >= $origy AND $origx > $max_x)
    {
    $faktor = $origx / $max_x;
    $new_x = $origx / $faktor;
    $new_y = $origy / $faktor;
    }

    elseif($origy > $origx AND $origy > $max_y)
    {
    $faktor = $origy / $max_y;
    $new_x = $origx / $faktor;
    $new_y = $origy / $faktor;
    }

    else
    {
    $new_x = $origx;
    $new_y = $origy;
    }

    // Squeeze and write it into a file
    $dst_img = imagecreatetruecolor($new_x,$new_y);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_x,$new_y,imagesx($src_img),imagesy($src_img));
    imagejpeg($dst_img, $fullthumbname, 50);
    }
    }

    // Function to show a thumbnail
    // -----------------------------------------------------------------
    function showthumb ($thumbdateiname, $thumbdateiendung)
    {
    $fullname = $thumbdateiname.$thumbdateiendung;
    $fullthumbname = $thumbdateiname."_t.jpg";
    if (file_exists($fullthumbname))
    {
    echo "<a href=\"$fullname\"><img src =\"$fullthumbname\" border=\"0\"></a>";
    echo "<!-- =========================== -->";
    echo "<!-- powered by TStarGallery 1.0 -->";
    echo "<!-- =========================== -->";

    }
    else
    {
    }

    }
    ?>
    Last edited by SomebodyNobody; Sep 28, 2006, 11:34 PM.

  • #2
    You can use Firepage's pagination script, it's awesome.

    Comment


    • #3
      Thanks for the link, but I don't have MySQL yet

      Comment


      • #4
        MySQL is not needed to use the Firepage pagination script. I got it working on a bunch of icon images in a directory, no MySQL anywhere to be seen.

        Comment


        • #5
          In the 3rd line it says:

          $max = mysql_result(
          mysql_query("SELECT COUNT(id) FROM colours WHERE id > 0"),
          0 ) ;

          and when I run the program it says:

          Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

          Comment


          • #6
            You might just have to put a teeny bit of effort into the process. Sorry.

            Here's the way I did it.
            PHP Code:
            // Instead of a database query, create an array of file names
            $iconArray glob('iconcatalog/*.gif');
            // Sort the array
            natcasesort($iconArray);
            $iconArray array_values($iconArray);
            // assign count
            $iconCount count($iconArray);
            // pagination setup as described in Firepage's instructions
            $pageSize 18;
            $pager = new pager$iconCount$pageSize, @$_GET['_p']); 
            $pager->set_range(10); 
            To display the icons, you have to emulate the LIMIT (n, m) functionality of MySQL. I did this with two counter variables, $i and $j. $i tracks the point at which array elements should start being displayed and $j tracks the point at which array elements should stop being displayed. These points are determined by calling the page class get_limit() function.
            PHP Code:
            $i 0;
            $j 0;
            echo 
            $pager->get_title('Page {CURRENT} of {MAX}')."<br />\n"
            echo 
            $pager->get_range('<a href="{LINK_HREF}">{LINK_LINK}</a>'' &nbsp; ''First''Last')."<br />\n";
            list(
            $start$nbr) = explode(","$pager->get_limit());
            foreach(
            $iconArray as $icon) {
                if (
            $i >= $start) {
                        print 
            "<div class=\"lefticon\">";
                        print 
            "<a href=\"#\" onclick=\"pickIcon('$icon');\"><img src=\"{$icon}\" width=\"80\" height=\"80\" class=\"imgblock\" alt=\"icon\" title=\"icon\"></a>";
                        print 
            "</div>\n";
                        
            $j++;
                }
                
            $i++;
                if (
            $j >= $nbr) {
                    break;
                }

            Comment

            Working...
            X