* Pass an array of images, with optional descriptions, to $img: * $a = array('IMG_2546.jpg', * 'IMG_2555.jpg', * 'IMG_2559.jpg' => 'Some Flowers' * ); * or a relative folder location; Thumbmaker caches the list of files so if you change the images, delete the cache file * include a function call where you want the images: * thumbmaker($a, $attrs); * The second parameter accepts an array with any of these elements: * 'show_filename' as bool: to show file names underneath each image (default false) * 'height' as int: force height (default 150) * 'columns' as int: number of table columns (default 3) * 'shrink_to_fit' as bool: scale width of image to that of height as well (e.g. 150px-high but 600px-wide images if false) (default true) * 'paging' as int: number of images to show per page (default no paging) * 'thumb_ext' as string: force the file extension for thumbnail (e.g. 'jpg') (default original file format) * 'cache_file_list' as bool: to prevent caching of the list of files (default true) * 'show_ident' as bool: to show ident/credit being displayed (default true) * 'ident_link' as string: raw HTML to add in ident (e.g. Flickr linkback) (default null) * 'title' as string: text to include as a title (H2). Creates unique anchor (default null) * 'toggle_vis' as bool: to initially hide image table, with clickable link to show/hide: have multiple large thumb tables in one page to avoid image downloads (default false) * @param array or string $img * @param array $params * @todo paging * @todo having some sort of collapsable thing so that thumbs are not loaded until user expands panel */ function thumbmaker($img, $params = null) { // var_dump($img); $cache_path = $_SERVER['DOCUMENT_ROOT'] . '/lib/cache/'; $folderlistcache_name = 'filelist'; // file of cache of folder contents //parse int vals ((int) $params['height'] > 0) ? $max_h = $params['height'] : $max_h = 150; ((int) $params['columns'] > 0) ? $cols = $params['columns'] : $cols = 3; //these vals are true unless explicitly false ($params['cache_file_list'] === false) ? $params['cache_file_list'] = false : $params['cache_file_list'] = true; ($params['shrink_to_fit'] === false) ? $params['shrink_to_fit'] = false : $params['shrink_to_fit'] = true; ($params['show_ident'] === false) ? $params['show_ident'] = false : $params['show_ident'] = true; if (is_string($img)) { // var_dump($img); // $img is a folder, determine its file list // point cache_path to the file list //deprecated with single cache dir //$cache_path = $img . $cache_path; // var_dump($cache_path); } else if (!is_array($img)) { // $img not a folder, nor an array, bail echo 'Thumbmaker wasn\'t given an folder or image list!'; return; } // if thumb folder doesn't exist, make it if (!file_exists($cache_path)) { if (!mkdir($cache_path, 777)) { echo "Thumbmaker couldn't make the cache folder '$cache_path'. Your web host may not allow it."; } } if (is_string($img)) { if ($params['cache_file_list'] && file_exists($cache_path . $folderlistcache_name)) { // we want file list cached, and it was $filelist = file($cache_path . $folderlistcache_name); $filelist = unserialize($filelist[0]); } else { // file list wasn't cached, get it $handle = @ opendir($img); //suppress error $filelist = array (); //being filelist if ($handle) { // keep going until all files in directory have been read while ($file = readdir($handle)) { // var_dump($file); // get extension and add in if it's an image $ext = substr($file, strrpos($file, '.')); // var_dump($ext); switch ($ext) { case '.gif' : case '.jpg' : case '.jpeg' : case '.png' : $filelist[] = $img . $file; } } // tidy up: close the handler closedir($handle); if ($params['cache_file_list']) { $handle = fopen($cache_path . $folderlistcache_name, 'w'); fwrite($handle, serialize($filelist)); fclose($handle); } } } } else { // filelist was given as input $filelist = $img; } if ($params['title'] > null) { //create title echo "\n