Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Micro Photo Album
09-22-2008, 07:26 PM
Post: #1
Micro Photo Album
Can someone modify this to support all images (including icons, if possible)?
PHP Code:
<?php
/*************************************************
 * Micro Photo Gallery
 *
 * Version: 1.0
 * Date: 2007-04-05
 *
 * Usage:
 * Just copy these files into your image folder
 *
 ****************************************************/

 
$columns     5;
 
$thmb_width  120;
 
$thmb_height 80;

function 
resizeImage($originalImage,$toWidth,$toHeight){
    
    
// Get the original geometry and calculate scales
    
list($width$height) = getimagesize($originalImage);
    
$xscale=$width/$toWidth;
    
$yscale=$height/$toHeight;
    
    
// Recalculate new size with default ratio
    
if ($yscale>$xscale){
        
$new_width round($width * (1/$yscale));
        
$new_height round($height * (1/$yscale));
    }
    else {
        
$new_width round($width * (1/$xscale));
        
$new_height round($height * (1/$xscale));
    }
    
// Resize the original image
    
$imageResized imagecreatetruecolor($new_width$new_height);
    
$imageTmp     imagecreatefromjpeg ($originalImage);
    
imagecopyresampled($imageResized$imageTmp0000$new_width$new_height$width$height);

    return 
$imageResized;


function 
generateThumbnails(){
    global 
$thmb_width,$thmb_height;
    
    
// Open the actual directory
    
if ($handle opendir(".")) {
        
// Read all file from the actual directory
        
while ($file readdir($handle))  {
            
// Check whether tha actual item is a valid file
            
if (is_file($file)){
                
// Check whether the actual image is a thumbnail
                  
if (strpos($file,'_th.jpg')){
                      
$isThumb true;
                  } else {
                      
$isThumb false;
                  }
              
                  if (!
$isThumb) {
                      
// Process the file string
                      
$dirName  substr($file,0,strpos($file,basename($file)));
                      if (
strlen($dirName) < 1$dirName '.';
                      
$fileName basename($file);
                      
$fileMain substr($fileName,0,strrpos($fileName,'.'));
                      
$extName  substr($fileName,strrpos($fileName,'.'),
                                          
strlen($fileName)-strrpos($fileName,'.'));
                      
                      
// Check if the actual file is a jpeg image
                      
if (($extName == '.jpg') || ($extName == '.jpeg')){
                        
$thmbFile $dirName.'/'.$fileMain.'_th.jpg';
                        
// If a thumbnail dosn't exists tahn create a new one
                        
if (!file_exists($thmbFile)){
                            
imagejpeg(resizeImage($file,$thmb_width,$thmb_height),$thmbFile,80);
                        }
                    }
                  } 
               }
           }
    }
    
}

function 
getNormalImage($file){
    
$base substr($file,0,strrpos($file,'_th.jpg'));
    if (
file_exists($base.'.jpg')) return $base.'.jpg';
    elseif (
file_exists($base.'.jpeg')) return $base.'.jpeg';
    else return 
"";
}

function 
displayPhotos(){
    global 
$columns;
    
    
generateThumbnails();
    
$act 0;
    
// Open the actual directory
    
if ($handle opendir(".")) {
        
// Read all file from the actual directory
        
while ($file readdir($handle))  {
            
// Check whether tha actual item is a valid file
            
if (is_file($file)){
                
// Check whether the actual image is a thumbnail
                  
if (strpos($file,'_th.jpg')){
                    ++
$act;
                    if (
$act $columns) {
                        echo 
'</tr><tr><td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';    
                        
$act 1;
                    } else {
                        echo 
'<td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';    
                    }
                      
                  }
              }
        }
    }    
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Micro Photo Gallery</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center><a href="http://zimmage.net84.net/microUpload.php"><b>Upload an Image</b></a></center>
  <div id="main">
    <div class="caption">Micro Photo Gallery</div>
      <table align="center"><tr>     
            <?php displayPhotos(); ?>
      </table>        
            
    <div id="source">Micro Photo Gallery 1.0</div>
  </div>
</body> 

[Image: zbanner5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-23-2008, 04:44 PM
Post: #2
RE: Micro Photo Album
Why not just use an existing gallery script?

Available for one-on-one support:
MSN: matt@phozop.net
AIM: phozofree
[Image: matt2qs5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-23-2008, 06:46 PM
Post: #3
RE: Micro Photo Album
This is an existing gallery script!

...

I meant to post this in the support forum.

[Image: zbanner5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-23-2008, 07:51 PM
Post: #4
RE: Micro Photo Album
Yes, but I meant one that handles what you want Wink

Available for one-on-one support:
MSN: matt@phozop.net
AIM: phozofree
[Image: matt2qs5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-23-2008, 08:48 PM
Post: #5
RE: Micro Photo Album
Quote:I meant to post this in the support forum.

You did, but then it was magically moved here.
Find all posts by this user
Quote this message in a reply
09-23-2008, 09:03 PM
Post: #6
RE: Micro Photo Album
It's not a support issue Wink

Available for one-on-one support:
MSN: matt@phozop.net
AIM: phozofree
[Image: matt2qs5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-24-2008, 07:40 AM
Post: #7
RE: Micro Photo Album
(09-23-2008 07:51 PM)Matt Wrote:  Yes, but I meant one that handles what you want Wink
This script is everything I want except it only displays jpgs and jpegs.

Can you please either tell me how to do it or do it for me?

[Image: zbanner5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-24-2008, 11:15 AM
Post: #8
RE: Micro Photo Album
All of the code using JPEG-specific stuff would have to be rewritten to
1) detect what file type is in use
2) handle file types other than JPEG

That's a lot of code, and I don't have the time to handle it.

Available for one-on-one support:
MSN: matt@phozop.net
AIM: phozofree
[Image: matt2qs5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-24-2008, 08:02 PM
Post: #9
RE: Micro Photo Album
I think I got all of it except, how would I modify this code to support .jpg, .png, .bmp, .gif, and .ico?
PHP Code:
function getNormalImage($file){
    
$base substr($file,0,strrpos($file,'_th.jpg'));
    if (
file_exists($base.'.jpg')) return $base.'.jpg';
    elseif (
file_exists($base.'.jpeg')) return $base.'.jpeg';
    else return 
"";


[Image: zbanner5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
09-24-2008, 09:22 PM
Post: #10
RE: Micro Photo Album
Well, for the $base line, determine what the file extension is and snip the right bit
Then, just add a bunch of if statements for file extensions.

Available for one-on-one support:
MSN: matt@phozop.net
AIM: phozofree
[Image: matt2qs5.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:

That One Forum
Contact UsPhozofree Free HostingReturn to TopReturn to ContentLite (Archive) ModeRSS Syndication