= strlen(CFG_THUMBNAIL_FILENAME_SUFFIX)) { if (substr($filename_base, strlen($filename_base) - strlen(CFG_THUMBNAIL_FILENAME_SUFFIX)) == CFG_THUMBNAIL_FILENAME_SUFFIX) return FALSE; } //Looks good. return TRUE; } //-------------------------------------------------------------------------------- //As a function of the file name, creates the file name for the thumbnail. function file_name_to_thumbnail_name($in_filename) { $extension_start = strrpos($in_filename, "."); //Find position of last "." in string. This should precede the //file extension. if ($extension_start === FALSE) { //"." not found. Should not happen. Filenames were checked in advance. echo "Fatal internal error at line " . __LINE__ . "\n"; exit(1); } $filename_prefix = substr($in_filename, 0, $extension_start); $filename_extension = substr($in_filename, $extension_start); $rv = $filename_prefix . CFG_THUMBNAIL_FILENAME_SUFFIX . $filename_extension; return $rv; } //-------------------------------------------------------------------------------- //Writes the index file preamble to the index file. This is very much //dependent on how the thumbnails will be used. This is currently customized //for what Dave Ashley does. function write_index_file_preamble($handle, $idstring) { fwrite($handle, "<" . "?" . "php\n"); fwrite($handle, "require_once(\"style/std/stdwpstyle.inc\");\n"); fwrite($handle, "?" . ">" . "\n"); fwrite($handle, "<" . "?" . "php\n"); fwrite($handle, " $" . "thispage = new StdWpStyle();\n"); fwrite($handle, "\n"); fwrite($handle, " $" . "thispage->static_page_header_title_std(\"" . $idstring . "\",\n"); fwrite($handle, " \"" . $idstring . "\",\n"); fwrite($handle, " \"\");\n"); fwrite($handle, " $" . "thispage->static_page_photo_thumbnail_explanation(TRUE, TRUE);\n"); fwrite($handle, "?" . ">" . "\n"); for ($i = 0; $i < CFG_INDEX_PARAGRAPH_INDENT; $i++) { fwrite($handle, " "); } fwrite($handle, "\n
\n"); } //-------------------------------------------------------------------------------- //Writes the index file postamble to the index file. This is very much //dependent on how the thumbnails will be used. This is currently customized //for what Dave Ashley does. function write_index_file_postamble($handle) { for ($i = 0; $i < CFG_INDEX_PARAGRAPH_INDENT; $i++) { fwrite($handle, " "); } fwrite($handle, "
\n\n"); fwrite($handle, "<" . "?" . "php\n"); fwrite($handle, " $" . "thispage->static_page_footer_std();\n"); fwrite($handle, "?" . ">" . "\n"); } //-------------------------------------------------------------------------------- //Writes a line to the index file corresponding to a linked larger picture //reprsented by a thumbnail. function write_index_line( $handle, $filename, $thumbnailname, $filename_filesize, $filename_xdim, $filename_ydim, $thumbnailname_filesize, $thumbnailname_xdim, $thumbnailname_ydim) { // //Indent. for ($i = 0; $i < CFG_INDEX_LINK_INDENT; $i++) { fwrite($handle, " "); } fwrite($handle, ""); fwrite($handle, "\n"); } //-------------------------------------------------------------------------------- //Write introductory message. hor_line_thick(); echo CFG_PROGNAME . " Copyright (C) 2015 David T. Ashley\n"; echo "This program comes with ABSOLUTELY NO WARRANTY; and is licensed under\n"; echo "the GNU General Public License, Version 3. A copy of this license is\n"; echo "provided in the source code of this program.\n"; hor_line_thin(); //----------------------------------------------------------------------------- //Get the date, time, and PID strings that will be used for the rest of the //script. $scr_datestring = date("Ymd_His"); $scr_pid = getmypid(); if ($scr_pid === FALSE) $scr_pid = 0; //----------------------------------------------------------------------------- //If the index file exists, rename it out of the way. This is to prevent //the loss of information. if (file_exists(CFG_INDEXFILE_NAME)) { rename(CFG_INDEXFILE_NAME, $scr_datestring . "_" . $scr_pid . ".php"); } //----------------------------------------------------------------------------- //Open the index file and write the preamble. $indexfile_handle = fopen(CFG_INDEXFILE_NAME, "w"); if ($indexfile_handle === FALSE) { echo "FATAL: unable to open index file.\n"; exit(1); } write_index_file_preamble($indexfile_handle, $scr_datestring . "_" . $scr_pid); //----------------------------------------------------------------------------- //Get and emit the names of everything in the directory. $file_list = get_file_names_in_dir(); if ($file_list === FALSE) { echo "List of files from PHP function scandir() is empty.\n"; echo "Serious internal error, or nothing to do. Script cannot continue.\n"; hor_line_thick(); exit(1); } else { echo "Files in working directory (unsorted, unfiltered, " . count($file_list) . " files):\n"; for ($i = 0; $i < count($file_list); $i++) echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n"; } hor_line_thin(); //----------------------------------------------------------------------------- //Remove the standard directory entries "." and ".." from the list, and //remove any directories. $temp_list = $file_list; unset($file_list); $n = 0; for ($i = 0; $i < count($temp_list); $i++) { //echo "Checking " . $temp_list[$i] . "\n"; if (strcmp($temp_list[$i], ".") == 0) { //. entry, not a file. } else if (strcmp($temp_list[$i], "..") == 0) { //.. entry, not a file. } else if (is_file($temp_list[$i])) { //This is a regular file. $file_list[] = $temp_list[$i]; $n++; } } if ($n == 0) $file_list = FALSE; unset($n); unset($temp_list); //----------------------------------------------------------------------------- //If there is nothing to do, end the script. if ($file_list === FALSE) { echo "No files to process.\n"; hor_line_thick(); exit(0); } //----------------------------------------------------------------------------- //Sort the list. This is a non-event. The only rationale for sorting is that //it ensures that the same set of files will be processed in the same order, //regardless of the order provided by the underlying OS internals. sort($file_list); //----------------------------------------------------------------------------- //Emit the names we now have. echo "Files in working directory (directory entries removed, sorted, " . count($file_list) . " files):\n"; for ($i = 0; $i < count($file_list); $i++) echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n"; hor_line_thin(); //----------------------------------------------------------------------------- //For each file in the list, process it. There are different processing //actions for each one. for ($i = 0; $i < count($file_list); $i++) { if (is_full_sized_image_file_name($file_list[$i])) { $thumbnail_name = file_name_to_thumbnail_name($file_list[$i]); $image_data = getimagesize($file_list[$i]); $thumbnail_data = getimagesize($thumbnail_name); write_index_line( $indexfile_handle, $file_list[$i], $thumbnail_name, filesize($file_list[$i]), $image_data[0], $image_data[1], filesize($thumbnail_name), $thumbnail_data[0], $thumbnail_data[1]); } } //----------------------------------------------------------------------------- //Complete and close up the index file. write_index_file_postamble($indexfile_handle); fclose($indexfile_handle); // $i = 0; // $completed = 0; // while (($completed < CFG_MAX_THUMBNAILS_PER_INVOCATION) && ($i < count($file_list))) // { // if (is_full_sized_image_file_name($file_list[$i])) // { // $thumbnail_name = file_name_to_thumbnail_name($file_list[$i]); // // if (file_exists($thumbnail_name)) // { // echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : skipping because corresponding thumbnail exists.\n"; // hor_line_thin(); // } // else // { // echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : creating thumbnail.\n"; // // echo "Creating thumbnail \"" . // $thumbnail_name . // "\" from image \"" . // $file_list[$i] . // "\".\n"; // // create_thumbnail($file_list[$i], // $thumbnail_name, // $filename_filesize, // $filename_xdim, // $filename_ydim, // $thumbnail_filesize, // $thumbnail_xdim, // $thumbnail_ydim); // // echo "Conversion complete.\n"; // echo " Full-sized image file size/xdim/ydim = " . // $filename_filesize . "/" . $filename_xdim . "/" . $filename_ydim . // ",\n"; // echo " Thumbnail image filesize/xdim/ydim = " . // $thumbnail_filesize . "/" . $thumbnail_xdim . "/" . $thumbnail_ydim . // ",\n"; // // hor_line_thin(); // $completed++; // } // } // else // { // //Unsuitable base name. Can't use it. // echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : skipping due to unsuitable name.\n"; // hor_line_thin(); // } // // $i++; // } // // //Emit a message about whether the program should be run again. I am aware of // //the uncovered case--where the last thumbnail was made on the last iteration // //of this invocation--but I will leave it uncovered for now. All that happens // //is the user runs the program unnecessarily one more time. // if ($completed == 0) // { // echo "No thumbnails were created--this program is done creating thumbnails.\n"; // echo "It is not necessary to run this program again.\n"; // hor_line_thin(); // } // else // { // echo $completed . " thumbnail(s) were created. Please run this program repeatedly again\n"; // echo "until no more thumbnails are created.\n"; // hor_line_thin(); // } //-------------------------------------------------------------------------------- echo CFG_PROGNAME . " execution ends.\n"; hor_line_thick(); //-------------------------------------------------------------------------------- //End of File //-------------------------------------------------------------------------------- ?>