Page 1 of 1

gallery complications....

Posted: Tue Mar 08, 2005 9:42 am
by olegu
I have searched, (but not yet found) what I'm looking for...
I'm putting together a little CMS system (Am I reinventing the wheel you say, noo, you can't be serious ... :P ) And in this litte CMS I want a litlle gallery.
And this is where the trouble starts.
I'm looking for a semi simple gallery, that will easily blend and integrate with my excisting code.
this integrating must be on two levels.
  • 1 .the visual part, I don't want to write a complicated template code, just to have some images on my site
    2. I want some gallerys to be visible only to site members, so the gallery should allso integrate with my user database / login functions
(allso auto generated thumbnails would be great.. )

So far I have come up with to solutions, none of them ideal in my eyes: the first alternative is a bit inconvinient (sorry for wierd spelling) due to the need for having two seperate gallery scripts, and due to some includes to other folders.
the scond alternative would be great if I could just work out an easy way to include it. It seems that most advanced gallery scripts requires really advanced coders to successfully integrate,,, :(

So what I need to know is:
Is there a neat little gallery script out there (that I have not been able to track down) which actually fills my needs, or perhaps there is an advanced gallery script that is EASY to integrate (but that I have not yet been able to locate), or perhaps there is a completely different and still unknown solution to my problem.

-all help and feedback is welcome, and appreciated

-Olegu

Posted: Tue Mar 08, 2005 9:48 am
by feyd
Why not write it yourself? Most gallery scripts will or do have a set design to them. There are several thumbnail generation scripts that have been posted here.

Posted: Tue Mar 08, 2005 10:09 am
by pickle
Ya, I'd look at writing your own. I usually do, but that's because I like seeing if I can do it :)

The parts you need are:
thumbnail generation
image viewing/gallery navigation
restricting access

- Like ~feyd said, thumbnail generation is almost a moot point, as that's been done MANY times before.
- The gallery navigation may arguably be the most difficult part, but that depends on how complex you want to get (sounds like not very). The Gallery program (your second link) gives you the ability to create nested albums, but it sounds like you won't need that - just 1 level authenticated and not authenticated. In that case, it's just a matter of dumping the contents of a folder.
- restricting access could be fun :). Do you want to just split up your users into members/non-members, or do you want levels of membership as well? If you want just the former, then putting all member-only images in one folder and all public access images in another should work. The issue then is how to stop people accessing the images by typing in the URL of the image. Usually, that can be done by moving that folder outside the document root, and making a PHP page to display them. Another option is using an .htaccess file in that folder, but that might be more difficult to work into your authentication scheme.

All in all, not *that* difficult of a project, shouldn't take more than a couple of days if you keep at it.

Posted: Tue Mar 08, 2005 1:00 pm
by olegu
yeah, I guess I have to go face my writing-php-code-that-deals-with-the-file-system-fobia......
It bottoms out to the same conclusion that made me decide to code my own CMS : noone had made the script I was looking for :P

I think I want to do the album / navigation thing to by using database metadata, (like posts in a blog or something) That will probably make it easier to do access restriction, but the challenge will be to keep the database info, and the content of the file system in sync. (More feared php-code-that-deals-with-the-file-system needed i suppose... 8O )

Anyway, I really appreciate your feedback. It gave me the kick in the butt that I needed, to go and do the coding I fear the most....

and btw, I can't believe how slowe the devnetwork server is today... argh
-Olegu

Posted: Thu Mar 10, 2005 12:44 pm
by olegu
I'm stuck in a memory hole...
I've written quiite a bit of my very own gallery script (/me proud ... :D)
but I've run into a litlle headache:
on my LAMP test server, the script runs fast, but I get a fatal errror on using to much memory from apache.
on my windows easy php test server, the script is so slow that after resizing six images, i get a timeout error.
argh.

so I am hoping that some guru might read this post and and bring me som good adviise..

o yes, the code, I nearly forgot that...

Code: Select all

function image_resize($src,$dest,$maxWidth,$maxHeight,$quality=70) {
         if (file_exists($src)  && isset($dest)) { 
             // path info 
             $destInfo  = pathinfo($dest);

             // image src size 
             $srcSize  = getImageSize($src);
        
             // image dest size $destSize[0] = width, $destSize[1] = height 
             $srcRatio  = $srcSize[0]/$srcSize[1]; // width/height ratio 
             $destRatio = $maxWidth/$maxHeight; 

             if ($destRatio > $srcRatio) { 
                 $destSize[1] = $maxHeight; 
                 $destSize[0] = $maxHeight*$srcRatio; 
             } 
             else { 
                 $destSize[0] = $maxWidth; 
                 $destSize[1] = $maxWidth/$srcRatio; 
             }   
       
             // path rectification 
             if ($destInfo['extension'] == "gif") { 
                 $dest = substr_replace($dest, 'jpg', -3); 
             }            

             // true color image, with anti-aliasing 
             $destImage = imageCreateTrueColor($destSize[0],$destSize[1]); 

             //imageAntiAlias($destImage,true);
             
             // src image 
             switch ($srcSize[2]) { 
                 case 1: //GIF 
                 $srcImage = imageCreateFromGif($src); 
                 break; 
            
                 case 2: //JPEG 
                 $srcImage = imageCreateFromJpeg($src); 
                 break; 
                 
                 case 3: //PNG 
                 $srcImage = imageCreateFromPng($src); 
                 break; 

                 default: 
                 return false; 
                 break; 
             } 

             // resampling 
             imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);

             // generating image 
             switch ($srcSize[2]) { 
                 case 1: 
                 case 2: 
                 imageJpeg($destImage,$dest,$quality); 
                 break; 
                 
                 case 3: 
                 imagePng($destImage,$dest); 
                 break; 
             } 
             return true; 

         } 
         else { 
             return false; 
         } 
}

function create_thbnail_cache ()  {
         //this function creates a cahce of thumbnails and resized versions of really
         //large pictures for easier viewing

         //variables from config file
         global $table_prefix;
         global $gallery_folder;

         $query = "SELECT * FROM {$table_prefix}gallery";
         $result = mysql_query($query) or die(mysql_error());

         //now cycle trhroug all the entries in the gallery database table and create the needed files
         while ($row = mysql_fetch_array($result)) {
               $sub_dir = $gallery_folder . "/" . $row['dir'];
               $thb_cache = $sub_dir . "/thbcache";
               $reduced_cache = $sub_dir . "/redcache";

               //check if the cache directories exists, if they don't, create them
               print ("chceking for folder exist $thb_cache <br>");
               if (!is_dir($thb_cache)) {
                  mkdir($thb_cache);
                  print ("created folder $thb_cache <br>");
               }
               print ("chceking for folder exist $reduced_cache <br>");
               if (!is_dir($reduced_cache)) {
                  mkdir($reduced_cache);
                  print ("created folder $reduced_cache <br>");
               }
               //now check if a thumbnail picture has been cached from the current image
               //if it is not, make one
               print ("checking if file exists: $thb_cache/thbc_{$row['filename']}<br>");
               if (!file_exists($thb_cache . "/thbc_" . $row['filename'])) {
                   print ("resizing (thb) {$row['filename']} <br>");
                   if (!image_resize($sub_dir . "/" . $row['filename'], $thb_cache . "/thbc_" . $row['filename'],
                                    100,100,$quality=70))
                   {
                   print ("resize error");
                   }
               }

               //now check if a reduced size picture has been cached from the current image
               //if it is not, make one
               print ("checking if file exists: $reduced_cache/thbc_{$row['filename']}<br>");
               if (!file_exists($reduced_cache . "/redc_" . $row['filename'])) {
                    print ("resizing (red) {$row['filename']} <br>");
                   if (!image_resize($sub_dir . "/" . $row['filename'], $reduced_cache . "/redc_" . $row['filename'],
                                    800,600,$quality=70))
                   {
                   print ("resize error");
                   }
               }
         }
}
the create_thbnail_cache () function loops the image_resize function. And some where in there is my horrible mistake...

any feedback recieved with gratitude

-Olegu

oh, and by the way, perhaps this subject should be moved to php code forum now?

Posted: Thu Mar 10, 2005 12:49 pm
by feyd
First problem I see if imagedestroy() isn't called.. GD has memory leaks, imagedestroy() helps clean this problem up. Next, is that GD can require a lot of memory to open an image. This was explained by myself in this thread: viewtopic.php?t=30239


Moved to PHP - Code.