Bigbruin.com
Home :: Reviews & Articles ::
Forum :: Info :: :: Facebook :: Youtube :: RSS Feed
Search  :: Register :: Log in
Script makes thumbnails for images in a folder
Go To Page 1, 2  Next
Post new topic   Reply to topic    Bigbruin.com Forum Index -> Software
View previous topic :: View next topic  
Author Message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Wed, 01 Dec 2004 13:32:22    Post Subject: Script makes thumbnails for images in a folder Reply with quote View Single Post

I think someone posted it on another forum I saw... But, I can't find it now. Basically, it was one file (perhaps .ASP extension) that you could drop into a folder of images on a server, and when you browsed to the folder you saw thumbnails instead of a list of file names.

Anyone know what I mean?

Sun
Back to top
View user's profile Send private message Visit poster's website
Little Bruin
Boo Boo

Joined: 07 Apr 2003
Posts: 667
Location: Pic-A-Nic Basket
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Wed, 01 Dec 2004 13:35:21    Post Subject: Reply with quote View Single Post

I've seen this (big surprise). Since you run PHP, I'll see what I can find for you.
_________________

A letter to a soldier
Back to top
View user's profile Send private message
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Wed, 01 Dec 2004 13:41:28    Post Subject: Reply with quote View Single Post

Do you have the GD Library installed?
_________________

A letter to a soldier
Back to top
View user's profile Send private message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Wed, 01 Dec 2004 13:45:35    Post Subject: Reply with quote View Single Post

Yes... I actually use that for a photo gallery on another site.
Back to top
View user's profile Send private message Visit poster's website
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Wed, 01 Dec 2004 14:04:38    Post Subject: Reply with quote View Single Post

Do you want it to resize the images everytime? Because you can have it a few ways:

1) Force PHP to resize all images each time. Lots of processing power, less bandwidth.

2) Have the browser render them all at a smaller resolution. (Little processing power, more bandwidth). When an image is clicked, it is already cached, so no load time to see the entire image.

3) Have PHP create a thumbnail folder and view that.

_________________

A letter to a soldier
Back to top
View user's profile Send private message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Wed, 01 Dec 2004 14:09:50    Post Subject: Reply with quote View Single Post

Probably #3... I think I found what I used before, but I can't run it right now:

http://wwwai.wu-wien.ac.at/~hahsler/pix2tn/

Very basic, but that is all I cared for on this little project. But, maybe I will install something else... Grin

Thanks!
Back to top
View user's profile Send private message Visit poster's website
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Wed, 01 Dec 2004 15:07:36    Post Subject: Reply with quote View Single Post

I found this... Seems like it would do what you want.

Code:
<?php
$gd2=checkgd();
$pics=directory("pics","jpg,JPG,JPEG,jpeg,png,PNG");
$pics=ditchtn($pics,"tn_");
if ($pics[0]!=""){
   foreach ($pics as $p){
      createthumb("pics/".$p,"thumbs/tn_".$p,150,150);
   }
}
/*
   Function checkgd()
   checks the version of gd, and returns "yes" when it's higher than 2
*/
function checkgd(){
   $gd2="";
   ob_start();
   phpinfo(8);
   $phpinfo=ob_get_contents();
   ob_end_clean();
   $phpinfo=strip_tags($phpinfo);
   $phpinfo=stristr($phpinfo,"gd version");
   $phpinfo=stristr($phpinfo,"version");
   preg_match('/\d/',$phpinfo,$gd);
   if ($gd[0]=='2'){$gd2="yes";}
   return $gd2;
}

/*
   Function ditchtn($arr,$thumbname)
   filters out thumbnails
*/
function ditchtn($arr,$thumbname){
   foreach ($arr as $item){
      if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;}
   }
   return $tmparr;
}

/*
   Function createthumb($name,$filename,$new_w,$new_h)
   creates a resized image
   variables:
   $name      Original filename
   $filename   Filename of the resized image
   $new_w      width of resized image
   $new_h      height of resized image
*/   
function createthumb($name,$filename,$new_w,$new_h){
   global $gd2;
   $system=explode(".",$name);
   if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
   if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
   $old_x=imageSX($src_img);
   $old_y=imageSY($src_img);
   if ($old_x > $old_y) {
      $thumb_w=$new_w;
      $thumb_h=$old_y*($new_h/$old_x);
   }
   if ($old_x < $old_y) {
      $thumb_w=$old_x*($new_w/$old_y);
      $thumb_h=$new_h;
   }
   if ($old_x == $old_y) {
      $thumb_w=$new_w;
      $thumb_h=$new_h;
   }
   if ($gd2==""){
         $dst_img=ImageCreate($thumb_w,$thumb_h);
         imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
   }else{
      $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
      imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
   }
   if (preg_match("/png/",$system[1])){
      imagepng($dst_img,$filename);
   } else {
      imagejpeg($dst_img,$filename);
   }
   imagedestroy($dst_img);
   imagedestroy($src_img);
}

/*
        Function directory($directory,$filters)
        reads the content of $directory, takes the files that apply to $filter
      and returns an array of the filenames.
        You can specify which files to read, for example
        $files = directory(".","jpg,gif");
                gets all jpg and gif files in this directory.
        $files = directory(".","all");
                gets all files.
*/
function directory($dir,$filters){
   $handle=opendir($dir);
   $files=array();
   if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
   if ($filters != "all"){
      $filters=explode(",",$filters);
      while (($file = readdir($handle))!==false) {
         for ($f=0;$f<sizeof($filters);$f++):
            $system=explode(".",$file);
            if ($system[1] == $filters[$f]){$files[] = $file;}
         endfor;
      }
   }
   closedir($handle);
   return $files;
}
?>
Back to top
View user's profile Send private message
Little Bruin
Boo Boo

Joined: 07 Apr 2003
Posts: 667
Location: Pic-A-Nic Basket
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Wed, 01 Dec 2004 16:14:19    Post Subject: Reply with quote View Single Post

so... just save as a .php file and run it? what about .gif files? looks like they aren't included!

thanks!
Back to top
View user's profile Send private message Visit poster's website
IceNine
*The Freshest*


Joined: 08 Sep 2003
Posts: 1459
Location: Bel Air

PostPosted: Wed, 01 Dec 2004 16:18:11    Post Subject: Reply with quote View Single Post

Gif... There was a huge problem among GD, PHP and Compuserve. The Graphics Interchange Format patent is owned by Compuserve, therefore the libraries necessary for this are not GNUly available.

I would check to see if your copy of GD has the GIF library installed.

_________________

A letter to a soldier
Back to top
View user's profile Send private message
Doctor Feelgood
Arrrrghh!


Joined: 07 Apr 2003
Posts: 20349
Location: New Jersey

PostPosted: Wed, 01 Dec 2004 16:22:15    Post Subject: Reply with quote View Single Post

I would check, but I am having a different software issue now... My office's firewall is now blocking every site on the web... except for this one!! WTF How is that possible? Laughing

"Request blocked by WebBlocker"
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Bigbruin.com Forum Index -> Software All times are GMT - 4 Hours
Go To Page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Contact Us :: On Facebook :: On Youtube :: Newsletter :: RSS Feed :: FAQ :: Links :: Sponsors :: Privacy Policy
Copyright © 2000 - 2023 Bigbruin.com - All rights reserved