/[dtapublic]/projs/trunk/libs/php/lib_dta/webpage_pic_org/indexfile_make.php
ViewVC logotype

Contents of /projs/trunk/libs/php/lib_dta/webpage_pic_org/indexfile_make.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (show annotations) (download)
Wed Oct 12 02:32:21 2016 UTC (7 years, 4 months ago) by dashley
File size: 55245 byte(s)
Initial checkin.
1 <?php
2 //--------------------------------------------------------------------------------
3 //indexfile_make.php, v0.1a, Copyright David T. Ashley, 2015
4 //--------------------------------------------------------------------------------
5 //This program, a PHP script, creates thumbnail images for recognized
6 //image files in the current working directory. This program is part of a
7 //3-program suite designed to collectively create a web page directly from
8 //digital camera files (and of course the web page can be customized by
9 //hand-editing after it is automatically generated). The supported process for
10 //creating a web page involves 3 programs (rather than 1) primarily to circumvent
11 //the involuntary process termination that will occur in some shared environments
12 //if a process consumes too much CPU time.
13 //
14 //The 3 programs in the 3-program suite are:
15 //
16 // filenames_canonize.php:
17 // Converts all names of files in a directory to lower-case, and makes
18 // substitutions for any unusual characters.
19 //
20 // thumbnails_make.php (this program):
21 // Creates thumbnails from recognized image types. The thumbnails are
22 // named relative to the original image file with the suffix "_small".
23 // Only 20 files are converted on each invocation of the program, to
24 // avoid the involuntary process termination that typically occurs in
25 // a shared hosting environment when a process uses too much CPU time.
26 // The program should be run repeatedly until it indicates that it has
27 // no more thumbnails to create.
28 //
29 // If any full-sized photos are modified, any corresponding thumbnails
30 // should be deleted and thumbnails_make.php and indexfile_make.php should
31 // be run again.
32 //
33 // indexfile_make.php
34 // Scans a directory and makes an index file ("index2.php") displaying
35 // all the thumbnail images, each of which link to the corresponding
36 // full-sized image. The index file is tailored to Dave Ashley's
37 // needs, but the created file can be edited and most of the content
38 // pasted into an HTML file. To avoid the accidental loss of
39 // information, any existing "index2.php" file is renamed out of the
40 // way.
41 //
42 //This script is designed to be run manually (rather than automatically invoked
43 //as a result of a web page request). It was written in PHP for convenience
44 //simply because DreamHost (the web hosting company Dave Ashley uses) has as part
45 //of its hosting environment PHP with the ImageMagick library compiled in.
46 //
47 //Usually, this script is invoked using "php <path>/indexfile_make.php", but the
48 //method of invocation may vary based on computing platform details.
49 //--------------------------------------------------------------------------------
50 //This program is free software: you can redistribute it and/or modify
51 //it under the terms of the GNU General Public License as published by
52 //the Free Software Foundation, either version 3 of the License, or
53 //(at your option) any later version.
54 //
55 //This program is distributed in the hope that it will be useful,
56 //but WITHOUT ANY WARRANTY; without even the implied warranty of
57 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58 //GNU General Public License for more details.
59 //
60 //The GNU General Public License is reproduced below, and also is
61 //available at http://www.gnu.org/licenses/.
62 //--------------------------------------------------------------------------------
63 // GNU GENERAL PUBLIC LICENSE
64 // Version 3, 29 June 2007
65 //
66 // Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
67 // Everyone is permitted to copy and distribute verbatim copies
68 // of this license document, but changing it is not allowed.
69 //
70 // Preamble
71 //
72 // The GNU General Public License is a free, copyleft license for
73 // software and other kinds of works.
74 //
75 // The licenses for most software and other practical works are designed
76 // to take away your freedom to share and change the works. By contrast,
77 // the GNU General Public License is intended to guarantee your freedom to
78 // share and change all versions of a program--to make sure it remains free
79 // software for all its users. We, the Free Software Foundation, use the
80 // GNU General Public License for most of our software; it applies also to
81 // any other work released this way by its authors. You can apply it to
82 // your programs, too.
83 //
84 // When we speak of free software, we are referring to freedom, not
85 // price. Our General Public Licenses are designed to make sure that you
86 // have the freedom to distribute copies of free software (and charge for
87 // them if you wish), that you receive source code or can get it if you
88 // want it, that you can change the software or use pieces of it in new
89 // free programs, and that you know you can do these things.
90 //
91 // To protect your rights, we need to prevent others from denying you
92 // these rights or asking you to surrender the rights. Therefore, you have
93 // certain responsibilities if you distribute copies of the software, or if
94 // you modify it: responsibilities to respect the freedom of others.
95 //
96 // For example, if you distribute copies of such a program, whether
97 // gratis or for a fee, you must pass on to the recipients the same
98 // freedoms that you received. You must make sure that they, too, receive
99 // or can get the source code. And you must show them these terms so they
100 // know their rights.
101 //
102 // Developers that use the GNU GPL protect your rights with two steps:
103 // (1) assert copyright on the software, and (2) offer you this License
104 // giving you legal permission to copy, distribute and/or modify it.
105 //
106 // For the developers' and authors' protection, the GPL clearly explains
107 // that there is no warranty for this free software. For both users' and
108 // authors' sake, the GPL requires that modified versions be marked as
109 // changed, so that their problems will not be attributed erroneously to
110 // authors of previous versions.
111 //
112 // Some devices are designed to deny users access to install or run
113 // modified versions of the software inside them, although the manufacturer
114 // can do so. This is fundamentally incompatible with the aim of
115 // protecting users' freedom to change the software. The systematic
116 // pattern of such abuse occurs in the area of products for individuals to
117 // use, which is precisely where it is most unacceptable. Therefore, we
118 // have designed this version of the GPL to prohibit the practice for those
119 // products. If such problems arise substantially in other domains, we
120 // stand ready to extend this provision to those domains in future versions
121 // of the GPL, as needed to protect the freedom of users.
122 //
123 // Finally, every program is threatened constantly by software patents.
124 // States should not allow patents to restrict development and use of
125 // software on general-purpose computers, but in those that do, we wish to
126 // avoid the special danger that patents applied to a free program could
127 // make it effectively proprietary. To prevent this, the GPL assures that
128 // patents cannot be used to render the program non-free.
129 //
130 // The precise terms and conditions for copying, distribution and
131 // modification follow.
132 //
133 // TERMS AND CONDITIONS
134 //
135 // 0. Definitions.
136 //
137 // "This License" refers to version 3 of the GNU General Public License.
138 //
139 // "Copyright" also means copyright-like laws that apply to other kinds of
140 // works, such as semiconductor masks.
141 //
142 // "The Program" refers to any copyrightable work licensed under this
143 // License. Each licensee is addressed as "you". "Licensees" and
144 // "recipients" may be individuals or organizations.
145 //
146 // To "modify" a work means to copy from or adapt all or part of the work
147 // in a fashion requiring copyright permission, other than the making of an
148 // exact copy. The resulting work is called a "modified version" of the
149 // earlier work or a work "based on" the earlier work.
150 //
151 // A "covered work" means either the unmodified Program or a work based
152 // on the Program.
153 //
154 // To "propagate" a work means to do anything with it that, without
155 // permission, would make you directly or secondarily liable for
156 // infringement under applicable copyright law, except executing it on a
157 // computer or modifying a private copy. Propagation includes copying,
158 // distribution (with or without modification), making available to the
159 // public, and in some countries other activities as well.
160 //
161 // To "convey" a work means any kind of propagation that enables other
162 // parties to make or receive copies. Mere interaction with a user through
163 // a computer network, with no transfer of a copy, is not conveying.
164 //
165 // An interactive user interface displays "Appropriate Legal Notices"
166 // to the extent that it includes a convenient and prominently visible
167 // feature that (1) displays an appropriate copyright notice, and (2)
168 // tells the user that there is no warranty for the work (except to the
169 // extent that warranties are provided), that licensees may convey the
170 // work under this License, and how to view a copy of this License. If
171 // the interface presents a list of user commands or options, such as a
172 // menu, a prominent item in the list meets this criterion.
173 //
174 // 1. Source Code.
175 //
176 // The "source code" for a work means the preferred form of the work
177 // for making modifications to it. "Object code" means any non-source
178 // form of a work.
179 //
180 // A "Standard Interface" means an interface that either is an official
181 // standard defined by a recognized standards body, or, in the case of
182 // interfaces specified for a particular programming language, one that
183 // is widely used among developers working in that language.
184 //
185 // The "System Libraries" of an executable work include anything, other
186 // than the work as a whole, that (a) is included in the normal form of
187 // packaging a Major Component, but which is not part of that Major
188 // Component, and (b) serves only to enable use of the work with that
189 // Major Component, or to implement a Standard Interface for which an
190 // implementation is available to the public in source code form. A
191 // "Major Component", in this context, means a major essential component
192 // (kernel, window system, and so on) of the specific operating system
193 // (if any) on which the executable work runs, or a compiler used to
194 // produce the work, or an object code interpreter used to run it.
195 //
196 // The "Corresponding Source" for a work in object code form means all
197 // the source code needed to generate, install, and (for an executable
198 // work) run the object code and to modify the work, including scripts to
199 // control those activities. However, it does not include the work's
200 // System Libraries, or general-purpose tools or generally available free
201 // programs which are used unmodified in performing those activities but
202 // which are not part of the work. For example, Corresponding Source
203 // includes interface definition files associated with source files for
204 // the work, and the source code for shared libraries and dynamically
205 // linked subprograms that the work is specifically designed to require,
206 // such as by intimate data communication or control flow between those
207 // subprograms and other parts of the work.
208 //
209 // The Corresponding Source need not include anything that users
210 // can regenerate automatically from other parts of the Corresponding
211 // Source.
212 //
213 // The Corresponding Source for a work in source code form is that
214 // same work.
215 //
216 // 2. Basic Permissions.
217 //
218 // All rights granted under this License are granted for the term of
219 // copyright on the Program, and are irrevocable provided the stated
220 // conditions are met. This License explicitly affirms your unlimited
221 // permission to run the unmodified Program. The output from running a
222 // covered work is covered by this License only if the output, given its
223 // content, constitutes a covered work. This License acknowledges your
224 // rights of fair use or other equivalent, as provided by copyright law.
225 //
226 // You may make, run and propagate covered works that you do not
227 // convey, without conditions so long as your license otherwise remains
228 // in force. You may convey covered works to others for the sole purpose
229 // of having them make modifications exclusively for you, or provide you
230 // with facilities for running those works, provided that you comply with
231 // the terms of this License in conveying all material for which you do
232 // not control copyright. Those thus making or running the covered works
233 // for you must do so exclusively on your behalf, under your direction
234 // and control, on terms that prohibit them from making any copies of
235 // your copyrighted material outside their relationship with you.
236 //
237 // Conveying under any other circumstances is permitted solely under
238 // the conditions stated below. Sublicensing is not allowed; section 10
239 // makes it unnecessary.
240 //
241 // 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
242 //
243 // No covered work shall be deemed part of an effective technological
244 // measure under any applicable law fulfilling obligations under article
245 // 11 of the WIPO copyright treaty adopted on 20 December 1996, or
246 // similar laws prohibiting or restricting circumvention of such
247 // measures.
248 //
249 // When you convey a covered work, you waive any legal power to forbid
250 // circumvention of technological measures to the extent such circumvention
251 // is effected by exercising rights under this License with respect to
252 // the covered work, and you disclaim any intention to limit operation or
253 // modification of the work as a means of enforcing, against the work's
254 // users, your or third parties' legal rights to forbid circumvention of
255 // technological measures.
256 //
257 // 4. Conveying Verbatim Copies.
258 //
259 // You may convey verbatim copies of the Program's source code as you
260 // receive it, in any medium, provided that you conspicuously and
261 // appropriately publish on each copy an appropriate copyright notice;
262 // keep intact all notices stating that this License and any
263 // non-permissive terms added in accord with section 7 apply to the code;
264 // keep intact all notices of the absence of any warranty; and give all
265 // recipients a copy of this License along with the Program.
266 //
267 // You may charge any price or no price for each copy that you convey,
268 // and you may offer support or warranty protection for a fee.
269 //
270 // 5. Conveying Modified Source Versions.
271 //
272 // You may convey a work based on the Program, or the modifications to
273 // produce it from the Program, in the form of source code under the
274 // terms of section 4, provided that you also meet all of these conditions:
275 //
276 // a) The work must carry prominent notices stating that you modified
277 // it, and giving a relevant date.
278 //
279 // b) The work must carry prominent notices stating that it is
280 // released under this License and any conditions added under section
281 // 7. This requirement modifies the requirement in section 4 to
282 // "keep intact all notices".
283 //
284 // c) You must license the entire work, as a whole, under this
285 // License to anyone who comes into possession of a copy. This
286 // License will therefore apply, along with any applicable section 7
287 // additional terms, to the whole of the work, and all its parts,
288 // regardless of how they are packaged. This License gives no
289 // permission to license the work in any other way, but it does not
290 // invalidate such permission if you have separately received it.
291 //
292 // d) If the work has interactive user interfaces, each must display
293 // Appropriate Legal Notices; however, if the Program has interactive
294 // interfaces that do not display Appropriate Legal Notices, your
295 // work need not make them do so.
296 //
297 // A compilation of a covered work with other separate and independent
298 // works, which are not by their nature extensions of the covered work,
299 // and which are not combined with it such as to form a larger program,
300 // in or on a volume of a storage or distribution medium, is called an
301 // "aggregate" if the compilation and its resulting copyright are not
302 // used to limit the access or legal rights of the compilation's users
303 // beyond what the individual works permit. Inclusion of a covered work
304 // in an aggregate does not cause this License to apply to the other
305 // parts of the aggregate.
306 //
307 // 6. Conveying Non-Source Forms.
308 //
309 // You may convey a covered work in object code form under the terms
310 // of sections 4 and 5, provided that you also convey the
311 // machine-readable Corresponding Source under the terms of this License,
312 // in one of these ways:
313 //
314 // a) Convey the object code in, or embodied in, a physical product
315 // (including a physical distribution medium), accompanied by the
316 // Corresponding Source fixed on a durable physical medium
317 // customarily used for software interchange.
318 //
319 // b) Convey the object code in, or embodied in, a physical product
320 // (including a physical distribution medium), accompanied by a
321 // written offer, valid for at least three years and valid for as
322 // long as you offer spare parts or customer support for that product
323 // model, to give anyone who possesses the object code either (1) a
324 // copy of the Corresponding Source for all the software in the
325 // product that is covered by this License, on a durable physical
326 // medium customarily used for software interchange, for a price no
327 // more than your reasonable cost of physically performing this
328 // conveying of source, or (2) access to copy the
329 // Corresponding Source from a network server at no charge.
330 //
331 // c) Convey individual copies of the object code with a copy of the
332 // written offer to provide the Corresponding Source. This
333 // alternative is allowed only occasionally and noncommercially, and
334 // only if you received the object code with such an offer, in accord
335 // with subsection 6b.
336 //
337 // d) Convey the object code by offering access from a designated
338 // place (gratis or for a charge), and offer equivalent access to the
339 // Corresponding Source in the same way through the same place at no
340 // further charge. You need not require recipients to copy the
341 // Corresponding Source along with the object code. If the place to
342 // copy the object code is a network server, the Corresponding Source
343 // may be on a different server (operated by you or a third party)
344 // that supports equivalent copying facilities, provided you maintain
345 // clear directions next to the object code saying where to find the
346 // Corresponding Source. Regardless of what server hosts the
347 // Corresponding Source, you remain obligated to ensure that it is
348 // available for as long as needed to satisfy these requirements.
349 //
350 // e) Convey the object code using peer-to-peer transmission, provided
351 // you inform other peers where the object code and Corresponding
352 // Source of the work are being offered to the general public at no
353 // charge under subsection 6d.
354 //
355 // A separable portion of the object code, whose source code is excluded
356 // from the Corresponding Source as a System Library, need not be
357 // included in conveying the object code work.
358 //
359 // A "User Product" is either (1) a "consumer product", which means any
360 // tangible personal property which is normally used for personal, family,
361 // or household purposes, or (2) anything designed or sold for incorporation
362 // into a dwelling. In determining whether a product is a consumer product,
363 // doubtful cases shall be resolved in favor of coverage. For a particular
364 // product received by a particular user, "normally used" refers to a
365 // typical or common use of that class of product, regardless of the status
366 // of the particular user or of the way in which the particular user
367 // actually uses, or expects or is expected to use, the product. A product
368 // is a consumer product regardless of whether the product has substantial
369 // commercial, industrial or non-consumer uses, unless such uses represent
370 // the only significant mode of use of the product.
371 //
372 // "Installation Information" for a User Product means any methods,
373 // procedures, authorization keys, or other information required to install
374 // and execute modified versions of a covered work in that User Product from
375 // a modified version of its Corresponding Source. The information must
376 // suffice to ensure that the continued functioning of the modified object
377 // code is in no case prevented or interfered with solely because
378 // modification has been made.
379 //
380 // If you convey an object code work under this section in, or with, or
381 // specifically for use in, a User Product, and the conveying occurs as
382 // part of a transaction in which the right of possession and use of the
383 // User Product is transferred to the recipient in perpetuity or for a
384 // fixed term (regardless of how the transaction is characterized), the
385 // Corresponding Source conveyed under this section must be accompanied
386 // by the Installation Information. But this requirement does not apply
387 // if neither you nor any third party retains the ability to install
388 // modified object code on the User Product (for example, the work has
389 // been installed in ROM).
390 //
391 // The requirement to provide Installation Information does not include a
392 // requirement to continue to provide support service, warranty, or updates
393 // for a work that has been modified or installed by the recipient, or for
394 // the User Product in which it has been modified or installed. Access to a
395 // network may be denied when the modification itself materially and
396 // adversely affects the operation of the network or violates the rules and
397 // protocols for communication across the network.
398 //
399 // Corresponding Source conveyed, and Installation Information provided,
400 // in accord with this section must be in a format that is publicly
401 // documented (and with an implementation available to the public in
402 // source code form), and must require no special password or key for
403 // unpacking, reading or copying.
404 //
405 // 7. Additional Terms.
406 //
407 // "Additional permissions" are terms that supplement the terms of this
408 // License by making exceptions from one or more of its conditions.
409 // Additional permissions that are applicable to the entire Program shall
410 // be treated as though they were included in this License, to the extent
411 // that they are valid under applicable law. If additional permissions
412 // apply only to part of the Program, that part may be used separately
413 // under those permissions, but the entire Program remains governed by
414 // this License without regard to the additional permissions.
415 //
416 // When you convey a copy of a covered work, you may at your option
417 // remove any additional permissions from that copy, or from any part of
418 // it. (Additional permissions may be written to require their own
419 // removal in certain cases when you modify the work.) You may place
420 // additional permissions on material, added by you to a covered work,
421 // for which you have or can give appropriate copyright permission.
422 //
423 // Notwithstanding any other provision of this License, for material you
424 // add to a covered work, you may (if authorized by the copyright holders of
425 // that material) supplement the terms of this License with terms:
426 //
427 // a) Disclaiming warranty or limiting liability differently from the
428 // terms of sections 15 and 16 of this License; or
429 //
430 // b) Requiring preservation of specified reasonable legal notices or
431 // author attributions in that material or in the Appropriate Legal
432 // Notices displayed by works containing it; or
433 //
434 // c) Prohibiting misrepresentation of the origin of that material, or
435 // requiring that modified versions of such material be marked in
436 // reasonable ways as different from the original version; or
437 //
438 // d) Limiting the use for publicity purposes of names of licensors or
439 // authors of the material; or
440 //
441 // e) Declining to grant rights under trademark law for use of some
442 // trade names, trademarks, or service marks; or
443 //
444 // f) Requiring indemnification of licensors and authors of that
445 // material by anyone who conveys the material (or modified versions of
446 // it) with contractual assumptions of liability to the recipient, for
447 // any liability that these contractual assumptions directly impose on
448 // those licensors and authors.
449 //
450 // All other non-permissive additional terms are considered "further
451 // restrictions" within the meaning of section 10. If the Program as you
452 // received it, or any part of it, contains a notice stating that it is
453 // governed by this License along with a term that is a further
454 // restriction, you may remove that term. If a license document contains
455 // a further restriction but permits relicensing or conveying under this
456 // License, you may add to a covered work material governed by the terms
457 // of that license document, provided that the further restriction does
458 // not survive such relicensing or conveying.
459 //
460 // If you add terms to a covered work in accord with this section, you
461 // must place, in the relevant source files, a statement of the
462 // additional terms that apply to those files, or a notice indicating
463 // where to find the applicable terms.
464 //
465 // Additional terms, permissive or non-permissive, may be stated in the
466 // form of a separately written license, or stated as exceptions;
467 // the above requirements apply either way.
468 //
469 // 8. Termination.
470 //
471 // You may not propagate or modify a covered work except as expressly
472 // provided under this License. Any attempt otherwise to propagate or
473 // modify it is void, and will automatically terminate your rights under
474 // this License (including any patent licenses granted under the third
475 // paragraph of section 11).
476 //
477 // However, if you cease all violation of this License, then your
478 // license from a particular copyright holder is reinstated (a)
479 // provisionally, unless and until the copyright holder explicitly and
480 // finally terminates your license, and (b) permanently, if the copyright
481 // holder fails to notify you of the violation by some reasonable means
482 // prior to 60 days after the cessation.
483 //
484 // Moreover, your license from a particular copyright holder is
485 // reinstated permanently if the copyright holder notifies you of the
486 // violation by some reasonable means, this is the first time you have
487 // received notice of violation of this License (for any work) from that
488 // copyright holder, and you cure the violation prior to 30 days after
489 // your receipt of the notice.
490 //
491 // Termination of your rights under this section does not terminate the
492 // licenses of parties who have received copies or rights from you under
493 // this License. If your rights have been terminated and not permanently
494 // reinstated, you do not qualify to receive new licenses for the same
495 // material under section 10.
496 //
497 // 9. Acceptance Not Required for Having Copies.
498 //
499 // You are not required to accept this License in order to receive or
500 // run a copy of the Program. Ancillary propagation of a covered work
501 // occurring solely as a consequence of using peer-to-peer transmission
502 // to receive a copy likewise does not require acceptance. However,
503 // nothing other than this License grants you permission to propagate or
504 // modify any covered work. These actions infringe copyright if you do
505 // not accept this License. Therefore, by modifying or propagating a
506 // covered work, you indicate your acceptance of this License to do so.
507 //
508 // 10. Automatic Licensing of Downstream Recipients.
509 //
510 // Each time you convey a covered work, the recipient automatically
511 // receives a license from the original licensors, to run, modify and
512 // propagate that work, subject to this License. You are not responsible
513 // for enforcing compliance by third parties with this License.
514 //
515 // An "entity transaction" is a transaction transferring control of an
516 // organization, or substantially all assets of one, or subdividing an
517 // organization, or merging organizations. If propagation of a covered
518 // work results from an entity transaction, each party to that
519 // transaction who receives a copy of the work also receives whatever
520 // licenses to the work the party's predecessor in interest had or could
521 // give under the previous paragraph, plus a right to possession of the
522 // Corresponding Source of the work from the predecessor in interest, if
523 // the predecessor has it or can get it with reasonable efforts.
524 //
525 // You may not impose any further restrictions on the exercise of the
526 // rights granted or affirmed under this License. For example, you may
527 // not impose a license fee, royalty, or other charge for exercise of
528 // rights granted under this License, and you may not initiate litigation
529 // (including a cross-claim or counterclaim in a lawsuit) alleging that
530 // any patent claim is infringed by making, using, selling, offering for
531 // sale, or importing the Program or any portion of it.
532 //
533 // 11. Patents.
534 //
535 // A "contributor" is a copyright holder who authorizes use under this
536 // License of the Program or a work on which the Program is based. The
537 // work thus licensed is called the contributor's "contributor version".
538 //
539 // A contributor's "essential patent claims" are all patent claims
540 // owned or controlled by the contributor, whether already acquired or
541 // hereafter acquired, that would be infringed by some manner, permitted
542 // by this License, of making, using, or selling its contributor version,
543 // but do not include claims that would be infringed only as a
544 // consequence of further modification of the contributor version. For
545 // purposes of this definition, "control" includes the right to grant
546 // patent sublicenses in a manner consistent with the requirements of
547 // this License.
548 //
549 // Each contributor grants you a non-exclusive, worldwide, royalty-free
550 // patent license under the contributor's essential patent claims, to
551 // make, use, sell, offer for sale, import and otherwise run, modify and
552 // propagate the contents of its contributor version.
553 //
554 // In the following three paragraphs, a "patent license" is any express
555 // agreement or commitment, however denominated, not to enforce a patent
556 // (such as an express permission to practice a patent or covenant not to
557 // sue for patent infringement). To "grant" such a patent license to a
558 // party means to make such an agreement or commitment not to enforce a
559 // patent against the party.
560 //
561 // If you convey a covered work, knowingly relying on a patent license,
562 // and the Corresponding Source of the work is not available for anyone
563 // to copy, free of charge and under the terms of this License, through a
564 // publicly available network server or other readily accessible means,
565 // then you must either (1) cause the Corresponding Source to be so
566 // available, or (2) arrange to deprive yourself of the benefit of the
567 // patent license for this particular work, or (3) arrange, in a manner
568 // consistent with the requirements of this License, to extend the patent
569 // license to downstream recipients. "Knowingly relying" means you have
570 // actual knowledge that, but for the patent license, your conveying the
571 // covered work in a country, or your recipient's use of the covered work
572 // in a country, would infringe one or more identifiable patents in that
573 // country that you have reason to believe are valid.
574 //
575 // If, pursuant to or in connection with a single transaction or
576 // arrangement, you convey, or propagate by procuring conveyance of, a
577 // covered work, and grant a patent license to some of the parties
578 // receiving the covered work authorizing them to use, propagate, modify
579 // or convey a specific copy of the covered work, then the patent license
580 // you grant is automatically extended to all recipients of the covered
581 // work and works based on it.
582 //
583 // A patent license is "discriminatory" if it does not include within
584 // the scope of its coverage, prohibits the exercise of, or is
585 // conditioned on the non-exercise of one or more of the rights that are
586 // specifically granted under this License. You may not convey a covered
587 // work if you are a party to an arrangement with a third party that is
588 // in the business of distributing software, under which you make payment
589 // to the third party based on the extent of your activity of conveying
590 // the work, and under which the third party grants, to any of the
591 // parties who would receive the covered work from you, a discriminatory
592 // patent license (a) in connection with copies of the covered work
593 // conveyed by you (or copies made from those copies), or (b) primarily
594 // for and in connection with specific products or compilations that
595 // contain the covered work, unless you entered into that arrangement,
596 // or that patent license was granted, prior to 28 March 2007.
597 //
598 // Nothing in this License shall be construed as excluding or limiting
599 // any implied license or other defenses to infringement that may
600 // otherwise be available to you under applicable patent law.
601 //
602 // 12. No Surrender of Others' Freedom.
603 //
604 // If conditions are imposed on you (whether by court order, agreement or
605 // otherwise) that contradict the conditions of this License, they do not
606 // excuse you from the conditions of this License. If you cannot convey a
607 // covered work so as to satisfy simultaneously your obligations under this
608 // License and any other pertinent obligations, then as a consequence you may
609 // not convey it at all. For example, if you agree to terms that obligate you
610 // to collect a royalty for further conveying from those to whom you convey
611 // the Program, the only way you could satisfy both those terms and this
612 // License would be to refrain entirely from conveying the Program.
613 //
614 // 13. Use with the GNU Affero General Public License.
615 //
616 // Notwithstanding any other provision of this License, you have
617 // permission to link or combine any covered work with a work licensed
618 // under version 3 of the GNU Affero General Public License into a single
619 // combined work, and to convey the resulting work. The terms of this
620 // License will continue to apply to the part which is the covered work,
621 // but the special requirements of the GNU Affero General Public License,
622 // section 13, concerning interaction through a network will apply to the
623 // combination as such.
624 //
625 // 14. Revised Versions of this License.
626 //
627 // The Free Software Foundation may publish revised and/or new versions of
628 // the GNU General Public License from time to time. Such new versions will
629 // be similar in spirit to the present version, but may differ in detail to
630 // address new problems or concerns.
631 //
632 // Each version is given a distinguishing version number. If the
633 // Program specifies that a certain numbered version of the GNU General
634 // Public License "or any later version" applies to it, you have the
635 // option of following the terms and conditions either of that numbered
636 // version or of any later version published by the Free Software
637 // Foundation. If the Program does not specify a version number of the
638 // GNU General Public License, you may choose any version ever published
639 // by the Free Software Foundation.
640 //
641 // If the Program specifies that a proxy can decide which future
642 // versions of the GNU General Public License can be used, that proxy's
643 // public statement of acceptance of a version permanently authorizes you
644 // to choose that version for the Program.
645 //
646 // Later license versions may give you additional or different
647 // permissions. However, no additional obligations are imposed on any
648 // author or copyright holder as a result of your choosing to follow a
649 // later version.
650 //
651 // 15. Disclaimer of Warranty.
652 //
653 // THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
654 // APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
655 // HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
656 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
657 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
658 // PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
659 // IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
660 // ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
661 //
662 // 16. Limitation of Liability.
663 //
664 // IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
665 // WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
666 // THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
667 // GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
668 // USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
669 // DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
670 // PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
671 // EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
672 // SUCH DAMAGES.
673 //
674 // 17. Interpretation of Sections 15 and 16.
675 //
676 // If the disclaimer of warranty and limitation of liability provided
677 // above cannot be given local legal effect according to their terms,
678 // reviewing courts shall apply local law that most closely approximates
679 // an absolute waiver of all civil liability in connection with the
680 // Program, unless a warranty or assumption of liability accompanies a
681 // copy of the Program in return for a fee.
682 //--------------------------------------------------------------------------------
683 //C O N F I G U R A T I O N
684 //--------------------------------------------------------------------------------
685 //Configuration switch combinations were not tested. E-mail me any program
686 //corrections (dashley@gmail.com).
687 define ("CFG_PROGNAME", "indexfile_make.php");
688 //Program name.
689 define ("CFG_CONSOLE_STD_LINE_LEN", 78);
690 //Number of characters per line preferred for console output.
691 define ("CFG_THUMBNAIL_FILENAME_SUFFIX", "_small");
692 //String added just before the filename extension to choose thumbnail names
693 //based on name of full-sized image.
694 define ("CFG_INDEXFILE_NAME", "index2.php");
695 //Name of the file containing the index. PHP code is assumed, but the
696 //file can be harvested for the HTML.
697 define ("CFG_INDEXFILE_PICREF_INDENT", 3);
698 //The number of spaces to indent each reference to a picture.
699 define ("CFG_FILEEXTENSIONS_PHOTO", "jpg/jpeg");
700 //The file extensions that will be recognized as photos.
701 define ("CFG_FILEEXTENSIONS_LINK", "mov");
702 //File extensions that will be linked to. All others will be mentioned
703 //in the generated output but not linked to.
704 //--------------------------------------------------------------------------------
705 //Repeats a character to the console output a certain number of times.
706 function rep_char_con($c, $n)
707 {
708 while ($n--)
709 echo $c;
710 }
711 //--------------------------------------------------------------------------------
712 //Writes a standard thick horizontal line to the console.
713 function hor_line_thick()
714 {
715 rep_char_con("=", CFG_CONSOLE_STD_LINE_LEN);
716 echo "\n";
717 }
718 //--------------------------------------------------------------------------------
719 //Writes a standard thin horizontal line to the console.
720 function hor_line_thin()
721 {
722 rep_char_con("-", CFG_CONSOLE_STD_LINE_LEN);
723 echo "\n";
724 }
725 //--------------------------------------------------------------------------------
726 //Returns an array of all files in the working directory.
727 //If no files can be found, returns FALSE.
728 function get_file_names_in_dir()
729 {
730 //Get directory list.
731 $rv = scandir (".");
732
733 //If the list is empty, something went wrong. Return FALSE.
734 if ($rv === FALSE)
735 return FALSE;
736
737 return $rv;
738 }
739 //--------------------------------------------------------------------------------
740 //Accepts a non-negative integer as an integer or a string. Adds commas in the
741 //right places to make it more human readable.
742 function int_nonneg_commanate($in_ui)
743 {
744 //Ensure the integer is an integer from PHP's point of view.
745 $in_ui = (int)$in_ui;
746
747 //If a negative number was passed in, clip it.
748 if ($in_ui < 0)
749 $in_ui = 0;
750
751 //Make a proper numerical string with commas out of it.
752 $s_ui = number_format($in_ui);
753
754 return $s_ui;
755 }
756 //--------------------------------------------------------------------------------
757 //Returns TRUE if a file name appears to be a valid full-sized image name,
758 //or FALSE otherwise.
759 function is_full_sized_image_file_name($in_filename)
760 {
761 //Convert the string name to all lower case. This will do for
762 //comparisons and tests.
763 $s = strtolower($s);
764
765 //Attempt to split the name into a base and an extension. Any failure
766 //means it is an unsuitable name.
767 $extension_start = strrpos($in_filename, ".");
768 //Find position of last "." in string. This should precede the
769 //file extension.
770
771 if ($extension_start === FALSE)
772 {
773 //Bad name. Unsuitable.
774 return FALSE;
775 }
776
777 //Calculate the base and extension.
778 $filename_base = substr($in_filename, 0, $extension_start);
779 $filename_extension = substr($in_filename, $extension_start + 1);
780
781 //If the extension is neither "jpg" nor "jpeg", it is unsuitable.
782 if (($filename_extension != "jpg") && ($filename_extension != "jpeg"))
783 return FALSE;
784
785 //If the filename base is empty, the filename is unsuitable.
786 if (strlen($filename_base) == 0)
787 return FALSE;
788
789 //If the last characters of the base are the CFG_THUMBNAIL_FILENAME_SUFFIX,
790 //the name is unsuitable.
791 if (strlen($filename_base) >= strlen(CFG_THUMBNAIL_FILENAME_SUFFIX))
792 {
793 if (substr($filename_base, strlen($filename_base) - strlen(CFG_THUMBNAIL_FILENAME_SUFFIX))
794 == CFG_THUMBNAIL_FILENAME_SUFFIX)
795 return FALSE;
796 }
797
798 //Looks good.
799 return TRUE;
800 }
801 //--------------------------------------------------------------------------------
802 //As a function of the file name, creates the file name for the thumbnail.
803 function file_name_to_thumbnail_name($in_filename)
804 {
805 $extension_start = strrpos($in_filename, ".");
806 //Find position of last "." in string. This should precede the
807 //file extension.
808 if ($extension_start === FALSE)
809 {
810 //"." not found. Should not happen. Filenames were checked in advance.
811 echo "Fatal internal error at line " . __LINE__ . "\n";
812 exit(1);
813 }
814
815 $filename_prefix = substr($in_filename, 0, $extension_start);
816 $filename_extension = substr($in_filename, $extension_start);
817
818 $rv = $filename_prefix . CFG_THUMBNAIL_FILENAME_SUFFIX . $filename_extension;
819
820 return $rv;
821 }
822 //--------------------------------------------------------------------------------
823 //Writes the index file preamble to the index file. This is very much
824 //dependent on how the thumbnails will be used. This is currently customized
825 //for what Dave Ashley does.
826 function write_index_file_preamble($handle, $idstring)
827 {
828 fwrite($handle, "<" . "?" . "php\n");
829 fwrite($handle, "require_once(\"style/std/stdwpstyle.inc\");\n");
830 fwrite($handle, "?" . ">" . "\n");
831 fwrite($handle, "<" . "?" . "php\n");
832 fwrite($handle, " $" . "thispage = new StdWpStyle();\n");
833 fwrite($handle, "\n");
834 fwrite($handle, " $" . "thispage->static_page_header_title_std(\"" . $idstring . "\",\n");
835 fwrite($handle, " \"" . $idstring . "\",\n");
836 fwrite($handle, " \"\");\n");
837 fwrite($handle, " $" . "thispage->static_page_photo_thumbnail_explanation(TRUE, TRUE);\n");
838 fwrite($handle, "?" . ">" . "\n");
839 for ($i = 0; $i < CFG_INDEX_PARAGRAPH_INDENT; $i++)
840 {
841 fwrite($handle, " ");
842 }
843 fwrite($handle, "\n<p align=\"center\">\n");
844 }
845 //--------------------------------------------------------------------------------
846 //Writes the index file postamble to the index file. This is very much
847 //dependent on how the thumbnails will be used. This is currently customized
848 //for what Dave Ashley does.
849 function write_index_file_postamble($handle)
850 {
851 for ($i = 0; $i < CFG_INDEX_PARAGRAPH_INDENT; $i++)
852 {
853 fwrite($handle, " ");
854 }
855 fwrite($handle, "</p>\n\n");
856 fwrite($handle, "<" . "?" . "php\n");
857 fwrite($handle, " $" . "thispage->static_page_footer_std();\n");
858 fwrite($handle, "?" . ">" . "\n");
859 }
860 //--------------------------------------------------------------------------------
861 //Writes a line to the index file corresponding to a linked larger picture
862 //reprsented by a thumbnail.
863 function write_index_line( $handle,
864 $filename,
865 $thumbnailname,
866 $filename_filesize,
867 $filename_xdim,
868 $filename_ydim,
869 $thumbnailname_filesize,
870 $thumbnailname_xdim,
871 $thumbnailname_ydim)
872 {
873 //<a href="dscn1258.jpg"><img border="0" src="dscn1258_small.jpg" alt="dscn1258.jpg (4932338 bytes)" width="125" height="93"></a>
874 //Indent.
875 for ($i = 0; $i < CFG_INDEX_LINK_INDENT; $i++)
876 {
877 fwrite($handle, " ");
878 }
879
880 fwrite($handle, "<a href=\"");
881 fwrite($handle, $filename);
882 fwrite($handle, "\"><img border=\"0\" src=\"");
883 fwrite($handle, $thumbnailname);
884 fwrite($handle, "\" alt=\"");
885 fwrite($handle, $filename);
886 fwrite($handle, " (");
887 fwrite($handle, int_nonneg_commanate($filename_filesize));
888 fwrite($handle, " bytes)\" ");
889 fwrite($handle, "title=\"");
890 fwrite($handle, $filename);
891 fwrite($handle, " (");
892 fwrite($handle, int_nonneg_commanate($filename_filesize));
893 fwrite($handle, " bytes)\" width=\"");
894 fwrite($handle, $thumbnailname_xdim);
895 fwrite($handle, "\" height=\"");
896 fwrite($handle, $thumbnailname_ydim);
897 fwrite($handle, "\"></a>");
898 fwrite($handle, "\n");
899 }
900 //--------------------------------------------------------------------------------
901 //Write introductory message.
902 hor_line_thick();
903 echo CFG_PROGNAME . " Copyright (C) 2015 David T. Ashley\n";
904 echo "This program comes with ABSOLUTELY NO WARRANTY; and is licensed under\n";
905 echo "the GNU General Public License, Version 3. A copy of this license is\n";
906 echo "provided in the source code of this program.\n";
907 hor_line_thin();
908 //-----------------------------------------------------------------------------
909 //Get the date, time, and PID strings that will be used for the rest of the
910 //script.
911 $scr_datestring = date("Ymd_His");
912 $scr_pid = getmypid();
913 if ($scr_pid === FALSE)
914 $scr_pid = 0;
915 //-----------------------------------------------------------------------------
916 //If the index file exists, rename it out of the way. This is to prevent
917 //the loss of information.
918 if (file_exists(CFG_INDEXFILE_NAME))
919 {
920 rename(CFG_INDEXFILE_NAME, $scr_datestring . "_" . $scr_pid . ".php");
921 }
922 //-----------------------------------------------------------------------------
923 //Open the index file and write the preamble.
924 $indexfile_handle = fopen(CFG_INDEXFILE_NAME, "w");
925 if ($indexfile_handle === FALSE)
926 {
927 echo "FATAL: unable to open index file.\n";
928 exit(1);
929 }
930 write_index_file_preamble($indexfile_handle, $scr_datestring . "_" . $scr_pid);
931 //-----------------------------------------------------------------------------
932 //Get and emit the names of everything in the directory.
933 $file_list = get_file_names_in_dir();
934 if ($file_list === FALSE)
935 {
936 echo "List of files from PHP function scandir() is empty.\n";
937 echo "Serious internal error, or nothing to do. Script cannot continue.\n";
938 hor_line_thick();
939 exit(1);
940 }
941 else
942 {
943 echo "Files in working directory (unsorted, unfiltered, "
944 .
945 count($file_list)
946 .
947 " files):\n";
948 for ($i = 0; $i < count($file_list); $i++)
949 echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n";
950 }
951 hor_line_thin();
952 //-----------------------------------------------------------------------------
953 //Remove the standard directory entries "." and ".." from the list, and
954 //remove any directories.
955 $temp_list = $file_list;
956 unset($file_list);
957 $n = 0;
958 for ($i = 0; $i < count($temp_list); $i++)
959 {
960 //echo "Checking " . $temp_list[$i] . "\n";
961
962 if (strcmp($temp_list[$i], ".") == 0)
963 {
964 //. entry, not a file.
965 }
966 else if (strcmp($temp_list[$i], "..") == 0)
967 {
968 //.. entry, not a file.
969 }
970 else if (is_file($temp_list[$i]))
971 {
972 //This is a regular file.
973 $file_list[] = $temp_list[$i];
974 $n++;
975 }
976 }
977
978 if ($n == 0)
979 $file_list = FALSE;
980
981 unset($n);
982 unset($temp_list);
983 //-----------------------------------------------------------------------------
984 //If there is nothing to do, end the script.
985 if ($file_list === FALSE)
986 {
987 echo "No files to process.\n";
988 hor_line_thick();
989 exit(0);
990 }
991 //-----------------------------------------------------------------------------
992 //Sort the list. This is a non-event. The only rationale for sorting is that
993 //it ensures that the same set of files will be processed in the same order,
994 //regardless of the order provided by the underlying OS internals.
995 sort($file_list);
996 //-----------------------------------------------------------------------------
997 //Emit the names we now have.
998 echo "Files in working directory (directory entries removed, sorted, "
999 .
1000 count($file_list)
1001 .
1002 " files):\n";
1003 for ($i = 0; $i < count($file_list); $i++)
1004 echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n";
1005 hor_line_thin();
1006
1007 //-----------------------------------------------------------------------------
1008 //For each file in the list, process it. There are different processing
1009 //actions for each one.
1010 for ($i = 0; $i < count($file_list); $i++)
1011 {
1012 if (is_full_sized_image_file_name($file_list[$i]))
1013 {
1014 $thumbnail_name = file_name_to_thumbnail_name($file_list[$i]);
1015
1016 $image_data = getimagesize($file_list[$i]);
1017 $thumbnail_data = getimagesize($thumbnail_name);
1018
1019 write_index_line( $indexfile_handle,
1020 $file_list[$i],
1021 $thumbnail_name,
1022 filesize($file_list[$i]),
1023 $image_data[0],
1024 $image_data[1],
1025 filesize($thumbnail_name),
1026 $thumbnail_data[0],
1027 $thumbnail_data[1]);
1028
1029 }
1030 }
1031
1032 //-----------------------------------------------------------------------------
1033 //Complete and close up the index file.
1034 write_index_file_postamble($indexfile_handle);
1035 fclose($indexfile_handle);
1036
1037 // $i = 0;
1038 // $completed = 0;
1039 // while (($completed < CFG_MAX_THUMBNAILS_PER_INVOCATION) && ($i < count($file_list)))
1040 // {
1041 // if (is_full_sized_image_file_name($file_list[$i]))
1042 // {
1043 // $thumbnail_name = file_name_to_thumbnail_name($file_list[$i]);
1044 //
1045 // if (file_exists($thumbnail_name))
1046 // {
1047 // echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : skipping because corresponding thumbnail exists.\n";
1048 // hor_line_thin();
1049 // }
1050 // else
1051 // {
1052 // echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : creating thumbnail.\n";
1053 //
1054 // echo "Creating thumbnail \"" .
1055 // $thumbnail_name .
1056 // "\" from image \"" .
1057 // $file_list[$i] .
1058 // "\".\n";
1059 //
1060 // create_thumbnail($file_list[$i],
1061 // $thumbnail_name,
1062 // $filename_filesize,
1063 // $filename_xdim,
1064 // $filename_ydim,
1065 // $thumbnail_filesize,
1066 // $thumbnail_xdim,
1067 // $thumbnail_ydim);
1068 //
1069 // echo "Conversion complete.\n";
1070 // echo " Full-sized image file size/xdim/ydim = " .
1071 // $filename_filesize . "/" . $filename_xdim . "/" . $filename_ydim .
1072 // ",\n";
1073 // echo " Thumbnail image filesize/xdim/ydim = " .
1074 // $thumbnail_filesize . "/" . $thumbnail_xdim . "/" . $thumbnail_ydim .
1075 // ",\n";
1076 //
1077 // hor_line_thin();
1078 // $completed++;
1079 // }
1080 // }
1081 // else
1082 // {
1083 // //Unsuitable base name. Can't use it.
1084 // echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : skipping due to unsuitable name.\n";
1085 // hor_line_thin();
1086 // }
1087 //
1088 // $i++;
1089 // }
1090 //
1091 // //Emit a message about whether the program should be run again. I am aware of
1092 // //the uncovered case--where the last thumbnail was made on the last iteration
1093 // //of this invocation--but I will leave it uncovered for now. All that happens
1094 // //is the user runs the program unnecessarily one more time.
1095 // if ($completed == 0)
1096 // {
1097 // echo "No thumbnails were created--this program is done creating thumbnails.\n";
1098 // echo "It is not necessary to run this program again.\n";
1099 // hor_line_thin();
1100 // }
1101 // else
1102 // {
1103 // echo $completed . " thumbnail(s) were created. Please run this program repeatedly again\n";
1104 // echo "until no more thumbnails are created.\n";
1105 // hor_line_thin();
1106 // }
1107 //--------------------------------------------------------------------------------
1108 echo CFG_PROGNAME . " execution ends.\n";
1109 hor_line_thick();
1110 //--------------------------------------------------------------------------------
1111 //End of File
1112 //--------------------------------------------------------------------------------
1113 ?>

Properties

Name Value
svn:executable *

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25