5 |
//This source code and any program in which it is compiled/used is provided under the MIT |
//This source code and any program in which it is compiled/used is provided under the MIT |
6 |
//LICENSE (full license text below). |
//LICENSE (full license text below). |
7 |
//------------------------------------------------------------------------------------------------- |
//------------------------------------------------------------------------------------------------- |
8 |
//Copyright (c) 2016 David T. Ashley |
//pics_indexfile_make.php, Copyright (c) 2016 David T. Ashley |
9 |
// |
// |
10 |
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
11 |
//associated documentation files (the "Software"), to deal in the Software without restriction, |
//associated documentation files (the "Software"), to deal in the Software without restriction, |
22 |
//DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
//DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 |
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24 |
//------------------------------------------------------------------------------------------------- |
//------------------------------------------------------------------------------------------------- |
25 |
|
//This program, a PHP script, creates an index file ("index2.php") based on the contents of the |
26 |
|
//working directory in which it is invoked. The index file created is tailored to Dave Ashley's |
27 |
|
//needs, but it can easily be hand-edited or this script can be modified. This program is part |
28 |
|
//of a 3-program suite designed to collectively create a web page directly from digital camera |
29 |
|
//files (and of course the web page can be customized by hand-editing after it is automatically |
30 |
|
//generated). |
31 |
|
// |
32 |
|
//The 3 programs in the 3-program suite are: |
33 |
|
// |
34 |
|
// pics_filenames_canonize.php: |
35 |
|
// Converts all names of files in a directory to lower-case, and makes substitutions for any |
36 |
|
// unusual characters. |
37 |
|
// |
38 |
|
// pics_thumbnails_make.php: |
39 |
|
// Creates thumbnails from recognized image types. The thumbnails are named relative to the |
40 |
|
// original image file with the suffix "_small". To support shared hosting environments where |
41 |
|
// CPU utilization of a script may be capped, there is a configuration constant in the script |
42 |
|
// that will perform only a fixed number of conversions per invocation. If this configuration |
43 |
|
// option is used, the script should be run repeatedly until it indicates that it has no more |
44 |
|
// thumbnails to create. |
45 |
|
// |
46 |
|
// If any full-sized photos are modified, any corresponding thumbnails should be deleted and |
47 |
|
// pics_thumbnails_make.php and pics_indexfile_make.php should be run again. |
48 |
|
// |
49 |
|
// pics_indexfile_make.php (this script): |
50 |
|
// Scans a directory and makes an index file ("index2.php") displaying all the thumbnail |
51 |
|
// images, each of which link to the corresponding full-sized image. The index file is |
52 |
|
// tailored to Dave Ashley's needs, but the created file can be edited and most of the |
53 |
|
// content pasted into an HTML file. To avoid the accidental loss of information, any |
54 |
|
// existing "index2.php" file is renamed out of the way. |
55 |
|
// |
56 |
|
//This script is designed to be run manually (rather than automatically invoked as a result of a |
57 |
|
//web page request). |
58 |
//-------------------------------------------------------------------------------- |
//-------------------------------------------------------------------------------- |
59 |
//C O N F I G U R A T I O N |
//C O N F I G U R A T I O N |
60 |
//-------------------------------------------------------------------------------- |
//-------------------------------------------------------------------------------- |
61 |
//Configuration switch combinations were not tested. E-mail me any program |
//Configuration switch combinations were not tested. E-mail me any program |
62 |
//corrections (dashley@gmail.com). |
//corrections (dashley@gmail.com). |
63 |
define ("CFG_PROGNAME", "indexfile_make.php"); |
define ("CFG_PROGNAME", "pics_indexfile_make.php"); |
64 |
//Program name. |
//Program name. |
65 |
define ("CFG_CONSOLE_STD_LINE_LEN", 78); |
define ("CFG_CONSOLE_STD_LINE_LEN", 78); |
66 |
//Number of characters per line preferred for console output. |
//Number of characters per line preferred for console output. |
70 |
define ("CFG_INDEXFILE_NAME", "index2.php"); |
define ("CFG_INDEXFILE_NAME", "index2.php"); |
71 |
//Name of the file containing the index. PHP code is assumed, but the |
//Name of the file containing the index. PHP code is assumed, but the |
72 |
//file can be harvested for the HTML. |
//file can be harvested for the HTML. |
73 |
|
define ("CFG_INDEX_LINK_INDENT", 3); |
74 |
|
//The number of spaces to indent each link. |
75 |
|
define ("CFG_INDEX_PARAGRAPH_INDENT", 3); |
76 |
|
//The number of spaces to indent each paragraph. |
77 |
define ("CFG_INDEXFILE_PICREF_INDENT", 3); |
define ("CFG_INDEXFILE_PICREF_INDENT", 3); |
78 |
//The number of spaces to indent each reference to a picture. |
//The number of spaces to indent each reference to a picture. |
79 |
define ("CFG_FILEEXTENSIONS_PHOTO", "jpg/jpeg"); |
define ("CFG_FILEEXTENSIONS_PHOTO", "jpg/jpeg/png/gif"); |
80 |
//The file extensions that will be recognized as photos. |
//The file extensions that will be recognized as photos. |
81 |
define ("CFG_FILEEXTENSIONS_LINK", "mov"); |
define ("CFG_FILEEXTENSIONS_LINK", "mov"); |
82 |
//File extensions that will be linked to. All others will be mentioned |
//File extensions that will be linked to. All others will be mentioned |
140 |
{ |
{ |
141 |
//Convert the string name to all lower case. This will do for |
//Convert the string name to all lower case. This will do for |
142 |
//comparisons and tests. |
//comparisons and tests. |
143 |
$s = strtolower($s); |
$in_filename = strtolower($in_filename); |
144 |
|
|
145 |
//Attempt to split the name into a base and an extension. Any failure |
//Attempt to split the name into a base and an extension. Any failure |
146 |
//means it is an unsuitable name. |
//means it is an unsuitable name. |
250 |
$thumbnailname_xdim, |
$thumbnailname_xdim, |
251 |
$thumbnailname_ydim) |
$thumbnailname_ydim) |
252 |
{ |
{ |
253 |
//<a href="dscn1258.jpg"><img border="0" src="dscn1258_small.jpg" alt="dscn1258.jpg (4932338 bytes)" width="125" height="93"></a> |
//<a href="dscn1258.jpg"><img border="0" src="dscn1258_small.jpg" alt="dscn1258.jpg (4932338 bytes)" width="125" height="93"></a> |
254 |
//Indent. |
//Indent. |
255 |
for ($i = 0; $i < CFG_INDEX_LINK_INDENT; $i++) |
for ($i = 0; $i < CFG_INDEX_LINK_INDENT; $i++) |
256 |
{ |
{ |
280 |
//-------------------------------------------------------------------------------- |
//-------------------------------------------------------------------------------- |
281 |
//Write introductory message. |
//Write introductory message. |
282 |
hor_line_thick(); |
hor_line_thick(); |
283 |
echo CFG_PROGNAME . " Copyright (C) 2015 David T. Ashley\n"; |
echo CFG_PROGNAME . ", Copyright (c) 2016 David T. Ashley\n"; |
284 |
echo "This program comes with ABSOLUTELY NO WARRANTY; and is licensed under\n"; |
echo "This program comes with ABSOLUTELY NO WARRANTY; and is licensed under the\n"; |
285 |
echo "the GNU General Public License, Version 3. A copy of this license is\n"; |
echo "MIT License. A copy of this license is provided in the source code\n"; |
286 |
echo "provided in the source code of this program.\n"; |
echo "of this program.\n"; |
287 |
hor_line_thin(); |
hor_line_thin(); |
288 |
//----------------------------------------------------------------------------- |
//----------------------------------------------------------------------------- |
289 |
//Get the date, time, and PID strings that will be used for the rest of the |
//Get the date, time, and PID strings that will be used for the rest of the |
413 |
//Complete and close up the index file. |
//Complete and close up the index file. |
414 |
write_index_file_postamble($indexfile_handle); |
write_index_file_postamble($indexfile_handle); |
415 |
fclose($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(); |
|
|
// } |
|
416 |
//-------------------------------------------------------------------------------- |
//-------------------------------------------------------------------------------- |
417 |
echo CFG_PROGNAME . " execution ends.\n"; |
echo CFG_PROGNAME . " execution ends.\n"; |
418 |
hor_line_thick(); |
hor_line_thick(); |