We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24449
    • 81 Posts
    Hi,

    The files I added to http://www.zombietuesday.com/autogallery in the last few days include an upload form that you are welcome to use and modify (GPL3). This form includes fields for title and description. There is also a Modify page that can add titles etc retrospectively.

    Currently the images are sorted alphabetically. If you want something more complex line 227 of AutoGallery.inc.php is where the sorting happens. The PHP sort command takes some arguments (http://php.net/manual/en/function.sort.php), or you can replace it with something more imaginative...

    The thumbnails are auto generated. AutoGallery takes tnwidth, tnheight, and quality arguments. This only happens the first time it is run. Feel free to delete the appropriate tn_ files if you have changed these args and they will regenerate.

    At the moment AutoGallery does not include any functionality for listing galleries or presenting a thumbnail to represent the gallery. It as intended to present a single gallery relevant to a particular page, or a particular topic. Our Shared World DOES have a gallery list (and, incidentally, the crude AJAX display thingy I mentioned before). Feel free to do a "view source" of http://www.oursharedworld.com/Media.html and mock my rush job. I will tidy it up and release it properly when I have more free time. It would also be a nice way of doing a flash scrolly gallery display if you don’t want the all-images-on-one-page approach of standard AutoGallery. The code for the gallery list snippet (which may not be compatible with an up-to-dte version of AutoGallery) is:
    <?php
    $result = "<gallerylist>\n";
    
    if($basepath == '') {
    $basepath = 'assets/galleries/';
    }
    
    if(substr($basepath, -1) != '/') {
      $basepath .= '/';
    }
    
    $dir = opendir($basepath);
    
    $output = '';
    $filelist = array();
    while($entry = readdir($dir)) {
      if(!(($entry == '..')||($entry == '.')||(substr($entry, 0, 3) == 'tn_'))) {
        array_push($filelist, $entry);
      }
    }
    
    sort($filelist);
    
    foreach($filelist as $entry) {
      $result .= "<gallery>\n";
      $result .= '   <name>' . $entry . "</name>\n";
     
      $result .= '   <thumbnail>';
      $subdir = opendir($basepath . $entry);
      while($subentry = readdir($subdir)) {
        if(substr($subentry, 0, 3) == 'tn_') {
          $result .= $basepath . $entry . '/' . $subentry;
          break;
        }    
      }
      $result .= "</thumbnail>\n";
      $result .= "</gallery>\n";
    }
    
    return $result . "</gallerylist>";
    ?>


    Don’t forget that the page this snippet is called from needs to have its content type set to XML (I spent ages trying to get JS to cope with it until I spotted the drop down under page settings...). As you can see, this will use the first tn_ it comes to as the gallery thumbnail. Again, change the sort line if you want something different.

    Hope this helps. Like I say, I’ll do a more pro job of it later.


    Ramsay
      • 24531
      • 213 Posts
      i downloaded latest ver. from you site, however, i got this problem. snippet is generating thumbnails at 190*245 and ignores tnwidth & tnheight parameters.
        • 24531
        • 213 Posts
        in addition, after upgrading to new version i got some weird problem with thumbnails. they’re awfully pixelized so i reverted to previous autoGallery version where generateTN looks like:

        function generateTN($srcfile, $tnimgpath, $tnwidth = 80, $tnheight = 80, $quality = 100) {
        
          $path_parts = pathinfo($srcfile);
        
          // Support only JPG and PNG
          if(strpos(' jpg, JPG, JPEG, jpeg', $path_parts['extension'])) {
            $sourceimg = imagecreatefromjpeg($srcfile);
          } else if(strpos(' png, PNG', $path_parts['extension'])) {
            $sourceimg = imagecreatefrompng($srcfile);
          } else {
            return NULL;
          }
          
          if($sourceimg) {
            $width = imagesx($sourceimg);
            $height = imagesy($sourceimg);
            
            // Create the thumbnail
            $shrunkwidth = round(($tnheight/$height) * $width);
            if($shrunkwidth < $tnwidth) {
              $shrunkheight = round(($tnwidth/$width) * $height);
              $snipsize = round(($shrunkheight - $tnheight) / 2);
              $shrunk = imagecreatetruecolor($tnwidth, $shrunkheight);
              imagecopyresized($shrunk, $sourceimg, 0, 0, 0, 0, $tnwidth, $shrunkheight, $width, $height);
              $targetimg = imagecreatetruecolor($tnwidth, $tnheight);
              imagecopy($targetimg, $shrunk, 0, 0, 0, $snipsize, $tnwidth, $tnheight);
            } else {
              $snipsize = round(($shrunkwidth - $tnwidth) / 2);
              $shrunk = imagecreatetruecolor($shrunkwidth, $tnheight);
              imagecopyresized($shrunk, $sourceimg, 0, 0, 0, 0, $shrunkwidth, $tnheight, $width, $height);
              $targetimg = imagecreatetruecolor($tnwidth, $tnheight);
              imagecopy($targetimg, $shrunk, 0, 0, $snipsize, 0, $tnwidth, $tnheight);
            }
            imagejpeg($targetimg, $tnimgpath, $quality);
            return $tnimgpath;
          } else {
            // We really shouldn't ever get here but I like to be complete.
            return NULL;
          } 
        }
        


        and hardcoded tnwidth and height.
          • 24449
          • 81 Posts
          Hi rav3n,

          Can you show us your snippet call? And check your AutoGallery snippet is up to date.

          Has anyone else had similar problems? I hate to respond with "it works for me" but it works for me... (but I might be expecting something odd).


          Ramsay
            • 23235
            • 40 Posts
            Is there a way to set the width in the snippet call and have the height automatically generate proportionally.
            When I try just setting the width (example: &tnwidth=`140`), i get a Parse Error.
              • 17282
              • 283 Posts
              The original idea behind this snippet was to create a crop of the image for the thumb rather than just a resized thumbnail ( so you can set the shape for thumbs .. ie always square regardless of original image orientation)

              .. so im suspecting that you cannot just set a width though im sure ramsay will correct me if im wrong .. he normally does smiley
                Everytime you use Flash ... a puppy dies .....
                R.G Taylor
                • 24449
                • 81 Posts
                Hi,

                You are both right apart from Martyn.... ( smiley )

                The idea was to crop the image, but then I changed the code to allow you to do exactly as you suggest: fix one dimension and get the other in proportion.

                However - as is the way when you don’t bother to properly comment and document things before making them open source - the various contributors have moved things around and lost that bit somewhere... If you download the version I have put on our site 5 mins ago it should now work properly.


                Ramsay
                  • 17282
                  • 283 Posts
                  Quote from: ramsay at Nov 05, 2009, 05:08 AM

                  Hi,

                  You are both right apart from Martyn.... ( smiley )



                  I wave my private parts at you .. you knees bent crawling sons of English Knigits!
                    Everytime you use Flash ... a puppy dies .....
                    R.G Taylor
                    • 23235
                    • 40 Posts
                    Two things.
                    1) It worked.
                    2) You rock! Thanks for the quick answer.
                      • 16004
                      • 10 Posts
                      Hi,

                      I’m a newb to MODx and autoGallery (and PHP), and would like to know if there is a place where I can find detailed, "step by step", instrusctions to implement autoGallery in a website.

                      So far I have set up all the snippets and chunks mentioned on zombietuesday.com, created a page called "gallery" in my MODx website and a folder containing a bunch of .jpgs on my harddrive.

                      Where do I go from here? What snippet or code do I put in my "gallery" page? What do I add to the MODx template?