$getImageResource[2]) { $maxHeight = round(($getImageResource[2]/$getImageResource[1])*$maxWidth); }
else { $maxWidth = round(($getImageResource[1]/$getImageResource[2])*$maxHeight); }
// Create resized image
$thumbnailResource = imagecreatetruecolor($maxWidth,$maxHeight);
imagecopyresized($thumbnailResource, $getImageResource[0], 0, 0, 0, 0, $maxWidth, $maxHeight, $getImageResource[1], $getImageResource[2]);
imagejpeg($thumbnailResource, $thumbnail, $thumbnailJpegQuality);
// Destroy image resources
imagedestroy($getImageResource[0]);
imagedestroy($thumbnailResource);
}
// Creates bolGallery files and returns the HTML layout source string
function bolGalleryCreate($imagesList, $referenceImagesDirectory, $tableColumnsNb, $thumbnailWidth, $thumbnailHeight, $switchClassic=false) {
// Build gallery HTML source
$HTML = "";
// Bolgallery Javascript popup function
// Build the HTML table to display all the thumbnails
$table_i=0;
foreach($imagesList as $currentImage) {
// (Re)build thumbnail url string
$referenceImageName = str_replace($referenceImagesDirectory, "", $currentImage);
$thumbnail = ($referenceImagesDirectory . "bolGallery/thumbnail_" . $referenceImageName);
// Get reference image file info
$referenceImageInfos = getimagesize($currentImage);
$referenceImageWidth = $referenceImageInfos[0];
$referenceImageHeight = $referenceImageInfos[1];
// Generate the thumbnail image if doesn't exist
if(! file_exists($thumbnail)) {
// Generate mode style thumbnail
if($switchClassic) { resizeImage($currentImage, $thumbnail, $thumbnailWidth, $thumbnailHeight); }
else { imageDetailExtract($currentImage, $thumbnail, $thumbnailWidth, $thumbnailHeight); }
}
// Display the thumbnail image and set a popup link to the big one
$alt = str_replace("_", " ", substr($referenceImageName, 0, -4));
$HTML .= "\t\t\t\t\t\t\t
"; // target attribute to be tested
$HTML .= "";
$HTML .= " | \n";
// HTML table next line evaluation
$table_i++;
if (($table_i % $tableColumnsNb) == 0) {
$HTML .= "\t\t\t\t\t\t\n\t\t\t\t\t\t\n";
}
}
return $HTML;
}
// Main function. Handles bolGalleryCreate(). Call it on your php pages where you want it build a gallery.
// Loads static page or lists reference images directory and launchs gallery creation
function bolGallery($referenceImagesDirectory, $tableColumnsNb, $thumbnailWidth, $thumbnailHeight, $switchClassic=false) {
$staticPage = ("./" . str_replace(".", "", str_replace("/", "", $referenceImagesDirectory)) . "_bolGalleryStaticPage.html");
// Recreate the gallery if there was any modification
if((!file_exists($staticPage)) or (filemtime($referenceImagesDirectory) > filemtime($staticPage))) {
// Builds an array (sorted by date) of image files from given directory
if (is_dir($referenceImagesDirectory)) {
// Create the thumbnails directory if doesn't exist
if (! is_dir($referenceImagesDirectory."bolGallery")) {
mkdir($referenceImagesDirectory."bolGallery", 0755);
}
// Check the reference images directory (Doesn't scan subdirectories)
$handle=opendir($referenceImagesDirectory);
while ($file=readdir($handle)) {
if (is_file($referenceImagesDirectory.$file)) {
// Check if the file is an image
$extension = strtolower(substr(strrchr($file, "." ), 1));
$supportedExtensions = array("jpg", "jpeg", "gif", "png");
if (in_array($extension, $supportedExtensions) and ($file[0] != "#")) { // Also checks whether file is marked by a "#"
// Add this file to the image files array
$imagesList[] = $referenceImagesDirectory.$file; // Should not add $referenceImagesDirectory in the array, could be added later
}
}
}
closedir($handle);
// Sort image files array by date with "mtime_sort" method
// Coders : could enable the user to choose between multiple file sorting
} else { die("" . $referenceImagesDirectory . " does not exist or is not a valid directory url. Cannot run bolGallery."); }
// Build gallery
$HTML = bolGalleryCreate($imagesList, $referenceImagesDirectory, $tableColumnsNb, $thumbnailWidth, $thumbnailHeight, $switchClassic);
// Bake also bolGallery HTML source output to file
$session = fopen($staticPage, "w"); // "r+" ?
fputs($session, "\n".$HTML);
fclose($session);
}
/* Won't work
// Load static page (the old one or the last created above)
require($staticPage) or die("" . $staticPage . " does not exist.");
*/
$pageString = file_get_contents($staticPage);
echo $pageString;
}
?>