Jump to content

sort photo's alphabetically


ericosman

Recommended Posts

Hello,

 

I got a script but i cant get 1 thing working :

 

Sort on alphabet

 

 

This is the  script i m using :

 

[thumb_gen.php]

 

<?php
//This file takes a value passed via a get variable, creates a thumbnail and outputs the thumbnail.

// change header information, so browser reads this file as an image
header('Content-type: image/jpeg');
function generateThumbnail($file) {
// get dimensions of target file
list($width, $height) = getimagesize($file);
// decide whether the image is portrait or landscape orientation
if($width > $height) $biggestSide = $width;
else $biggestSide = $height;
// create GD image
$current_image = imagecreatefromjpeg($file);
//The crop size will be half that of the largest side
$cropPercent = .5;
$cropWidth   = $biggestSide*$cropPercent;
$cropHeight  = $biggestSide*$cropPercent;
//getting the top left coordinate
$c1 = array("x"=>($width-$cropWidth)/2, "y"=>($height-$cropHeight)/2);
// resample
// if you want bigger thumbnails, change this value, it is defaulted at 100 px
$thumbSize = 100;
//create GD holding image object
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
//copy the cropped chunk of target file into out 100 x 100 thuumbnail
imagecopyresampled($thumb,$current_image, 0, 0, $c1['x'], $c1['y'], $thumbSize, $thumbSize, $cropWidth, $cropHeight);
//output thumbnail to this page.  if you wanted to save the thumbnail somewhere, change the null to a target file
imagejpeg($thumb, null, 50 );
}
// if the file has been passed a target, run function
if(!empty($_GET['target'])) {
generateThumbnail($_GET['target']);
}
?>

 

[gallery.php]

 

<?php
// Path to the folder which contains all of your image folders
$directory = "gallery";
// this is the page that you run the script on
$path = "index.php" . "?gallery=";
// This is the path to "thumbs.php" change this accordingly
$thumb_path = "thumb_gen.php";
// define opendir as a var
$scan = @opendir($directory) or die("Unable to open $directory");
// This array is used for storing the folder list, we will also use it to output a default directory if no gallery has been requested
$folders = array();
//This function lists all deirectories within the path specified by $directory
function genFolders($scan,$directory) {
     // Define these as global vatrs, so that we can use / update them inside the function
     global $path, $folders;
    // Open list tag, if you want to add css classes etc, alter the tag here
    echo '<ul>';
        while (false !== ($file = readdir($scan))) {
        $dir =$directory.'/'.$file;
            if(is_dir($dir) && $file != '.' && $file !='..' ) {
            array_push($folders, $dir);
                    $handle = @opendir($dir) or die("unable to open file $file");
            // output a link containing the folder name    
                //echo '<li><a href="' . $path .  $dir . '">' . $file . '</a></li>';
                    // Run function on file again if it is a folder, to check for other folders within
            genFolders($handle, $dir);
            }
    }
    //close list
        echo "</ul>";
    //close directory
        closedir($scan);
}

// This function outputs the thumbnails
function thumbOutput($target) {
    // define as global vars, so that we can use and update them in the function
    global $thumb_path;
    // open target directory, and output all image files within
    if ($handle = opendir($target)) {
        while (false !== ($file = readdir($handle))) {
            if (strpos($file, '.gif',1) ||strpos($file, '.jpg',1) || strpos($file, '.png',1) || strpos($file, '.JPG',1) || strpos($file, '.PNG',1) || strpos($file, '.GIF',1) ) {
                     echo '<a href="' . $target . '/' . $file . '" rel="launch"><img src="' . $thumb_path . '?target=' . $target . '/' . $file . '" class="thumb_img" border="0" /></a>';
            }
        }
        closedir($handle);
    }
}

// this function checks to see whether a specific directory has been requested, if not it uses the first value of the $folders array
function genThumbs() {
global $folders;
if(!empty($_GET['gallery'])) {
        thumbOutput($_GET['gallery']);
        } else {
        thumbOutput($folders[0]);
        }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/212106-sort-photos-alphabetically/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.