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

Contents of /projs/trunk/libs/php/lib_dta/webpage_pic_org/thumbnails_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, 9 months ago) by dashley
File size: 59205 byte(s)
Initial checkin.
1 <?php
2 //--------------------------------------------------------------------------------
3 //thumbnails_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>/thumbnails_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", "thumbnails_make.php");
688 //Number of characters per line preferred for console output.
689 define ("CFG_CONSOLE_STD_LINE_LEN", 78);
690 //Number of characters per line preferred for console output.
691 define ("CFG_THUMBNAIL_DIMENSION_MAX", 125);
692 //The maximum dimension of the created thumbnails. Thumbnails are sized so
693 //that the longest dimension is this many pixels.
694 define ("CFG_THUMBNAIL_BEVELED_BORDER_WIDTH", 4);
695 //The number of pixels that the thumbnail beveled borders should be.
696 define ("CFG_THUMBNAIL_FILENAME_SUFFIX", "_small");
697 //String added just before the filename extension to choose thumbnail names
698 //based on name of full-sized image.
699 define ("CFG_LANCZOS_FILTER_APPLY", FALSE);
700 //TRUE if should apply the Lanczos filter when making the thumbnail, FALSE
701 //otherwise. I have no idea if using a Lanczos filter improves the quality
702 //of the thumbnails, but the filter was applied in the PHP example I found
703 //online. Applying the Lanczos filter typically adds a few seconds to the
704 //time required to create each thumbnail.
705 define ("CFG_MAX_THUMBNAILS_PER_INVOCATION", 20);
706 //The maximum number of thumbnails that should be created per invocation.
707 //This is to prevent the program from being involuntarily terminated
708 //for taking too much CPU time.
709 //--------------------------------------------------------------------------------
710 //Calculates important integer indices related to creating a thumbnail, in order
711 //to minimize distortion in the thumbnail.
712 //
713 //When creating a thumbnail, the longer side may be relatively short (perhaps
714 //100 pixels), and the shorter side may be even shorter (perhaps even as short
715 //as 10 pixels). If the dimensions of the original image were not changed,
716 //converting the image to a thumbnail may result in distortion of up to about
717 //one percent. As an example, suppose that a 1600 x 900 image is converted to a
718 //thumbnail with the longer side of 125 pixels. The ideal dimension for the
719 //shorter side would be (900/1600) * 125 = 70.3125 pixels. The aspect ratio of
720 //the thumbnail can't be made to match the aspect ratio of the original image.
721 //
722 //To avoid any aspect ratio distortion that might be noticeable, this program
723 //chooses the shorter dimension for the thumbnail that is the ceiling of the actual
724 //quotient, then crops the longer dimension of the original image before the
725 //conversion to try and match the aspect ratios as closely as possible.
726 //
727 //In the example a paragraph or two above, the shorter side of the thumbnail
728 //would be chosen to be 71 pixels.
729 //
730 //Once this choice is made, we want to trim the original image before conversion
731 //so that n/900 is as close as possible to 125/71. n = (900 * 125) / 71 =
732 //1584.5070 pixels, so we choose 1585. This keeps the aspect ratio of the
733 //original image and the thumbnail as close as possible.
734 //
735 //Although the longer side of the original image may be reduced prior to the
736 //conversion to a thumbnail, this information is not written to disk, and
737 //the original image is not modified. The adjustment of the longer side is
738 //just a conversion trick to hopefully get better thumbnails.
739 function calc_thumbnail_conversion_pars
740 (
741 $in_orig_longer,
742 //Longer dimension of original image.
743 $in_orig_shorter,
744 //Shorter dimension of original image.
745 $in_thumbnail_longer,
746 //Longer dimension of desired thumbnail.
747 & $out_thumbnail_longer,
748 //Longer dimension of thumbnail that should be created.
749 & $out_thumbnail_shorter,
750 //Shorter dimension of thumbnail that should be created.
751 & $out_orig_crop_dim_longer,
752 //The size to crop to on the longer axis of the original.
753 & $out_orig_crop_dim_shorter,
754 //The size to crop to on the shorter axis of the original.
755 & $out_orig_crop_start_longer,
756 //For use with the Imagick:cropImage() method, the start
757 //position of the crop on the longer axis.
758 & $out_orig_crop_start_shorter
759 //For use with the Imagick:cropImage() method, the start
760 //position of the crop on the shorter axis.
761 )
762 {
763 //Set the thumbnail shorter dimension to the floor. This means would need to trim
764 //longest dimension of original to match aspect ratio as closely as possible.
765 $out_thumbnail_longer = $in_thumbnail_longer;
766 $out_thumbnail_shorter = ceil(((float)$in_thumbnail_longer *
767 (float)$in_orig_shorter) / (float)$in_orig_longer);
768 settype($out_thumbnail_shorter, "integer");
769
770 //The aspect ratio of the thumbnail is now set. Try to match the aspect ratio of the larger
771 //image as closely as possible by selecting a smaller number for the long axis of the
772 //original image.
773 $out_orig_crop_dim_longer = round(((float)$in_thumbnail_longer *
774 (float)$in_orig_shorter) / (float)$out_thumbnail_shorter);
775 settype($out_orig_crop_dim_longer, "integer");
776
777 //The original keeps its shorter dimension unchanged.
778 $out_orig_crop_dim_shorter = $in_orig_shorter;
779
780 //Set the cropping of the longer side of the original to cover half the necessary
781 //reduction.
782 $out_orig_crop_start_longer = round(((float)$in_orig_longer -
783 (float)$out_orig_crop_dim_longer) / 2.0);
784 settype($out_orig_crop_start_longer, "integer");
785
786 //No cropping of original shorter side.
787 $out_orig_crop_start_shorter = 0;
788 }
789 //--------------------------------------------------------------------------------
790 //Repeats a character to the console output a certain number of times.
791 function rep_char_con($c, $n)
792 {
793 while ($n--)
794 echo $c;
795 }
796 //--------------------------------------------------------------------------------
797 //Writes a standard thick horizontal line to the console.
798 function hor_line_thick()
799 {
800 rep_char_con("=", CFG_CONSOLE_STD_LINE_LEN);
801 echo "\n";
802 }
803 //--------------------------------------------------------------------------------
804 //Writes a standard thin horizontal line to the console.
805 function hor_line_thin()
806 {
807 rep_char_con("-", CFG_CONSOLE_STD_LINE_LEN);
808 echo "\n";
809 }
810 //--------------------------------------------------------------------------------
811 //Returns an array of all files in the working directory.
812 //If no files can be found, returns FALSE.
813 function get_file_names_in_dir()
814 {
815 //Get directory list.
816 $rv = scandir (".");
817
818 //If the list is empty, something went wrong. Return FALSE.
819 if ($rv === FALSE)
820 return FALSE;
821
822 return $rv;
823 }
824 //--------------------------------------------------------------------------------
825 //Returns TRUE if a file name appears to be a valid full-sized image name,
826 //or FALSE otherwise.
827 function is_full_sized_image_file_name($in_filename)
828 {
829 //Convert the string name to all lower case. This will do for
830 //comparisons and tests.
831 $s = strtolower($s);
832
833 //Attempt to split the name into a base and an extension. Any failure
834 //means it is an unsuitable name.
835 $extension_start = strrpos($in_filename, ".");
836 //Find position of last "." in string. This should precede the
837 //file extension.
838
839 if ($extension_start === FALSE)
840 {
841 //Bad name. Unsuitable.
842 return FALSE;
843 }
844
845 //Calculate the base and extension.
846 $filename_base = substr($in_filename, 0, $extension_start);
847 $filename_extension = substr($in_filename, $extension_start + 1);
848
849 //If the extension is neither "jpg" nor "jpeg", it is unsuitable.
850 if (($filename_extension != "jpg") && ($filename_extension != "jpeg"))
851 return FALSE;
852
853 //If the filename base is empty, the filename is unsuitable.
854 if (strlen($filename_base) == 0)
855 return FALSE;
856
857 //If the last characters of the base are the CFG_THUMBNAIL_FILENAME_SUFFIX,
858 //the name is unsuitable.
859 if (strlen($filename_base) >= strlen(CFG_THUMBNAIL_FILENAME_SUFFIX))
860 {
861 if (substr($filename_base, strlen($filename_base) - strlen(CFG_THUMBNAIL_FILENAME_SUFFIX))
862 == CFG_THUMBNAIL_FILENAME_SUFFIX)
863 return FALSE;
864 }
865
866 //Looks good.
867 return TRUE;
868 }
869 //--------------------------------------------------------------------------------
870 //As a function of the file name, creates the file name for the thumbnail.
871 function file_name_to_thumbnail_name($in_filename)
872 {
873 $extension_start = strrpos($in_filename, ".");
874 //Find position of last "." in string. This should precede the
875 //file extension.
876 if ($extension_start === FALSE)
877 {
878 //"." not found. Should not happen. Filenames were checked in advance.
879 echo "Fatal internal error at line " . __LINE__ . "\n";
880 exit(1);
881 }
882
883 $filename_prefix = substr($in_filename, 0, $extension_start);
884 $filename_extension = substr($in_filename, $extension_start);
885
886 $rv = $filename_prefix . CFG_THUMBNAIL_FILENAME_SUFFIX . $filename_extension;
887
888 return $rv;
889 }
890 //--------------------------------------------------------------------------------
891 //Actually creates the thumbnail, and returns some information about what was
892 //done.
893 //
894 //The calls to the ImagMagick library take on the order of 5s per image if there
895 //is filtering.
896 function create_thumbnail( $in_filename,
897 $in_thumbnailname,
898 & $out_filename_filesize,
899 & $out_filename_xdim,
900 & $out_filename_ydim,
901 & $out_thumbnailname_filesize,
902 & $out_thumbnailname_xdim,
903 & $out_thumbnailname_ydim)
904 {
905 //Assign output parameters just in case something doesn't get assigned.
906 $out_filename_filesize = 0;
907 $out_filename_xdim = 0;
908 $out_filename_ydim = 0;
909 $out_thumbnailname_filesize = 0;
910 $out_thumbnailname_xdim = 0;
911 $out_thumbnailname_ydim = 0;
912
913 //Establish target dimensions. Two cases, depending on which is the longer
914 //side.
915
916 //Construct.
917 $imagick = new Imagick();
918
919 //Load image.
920 $imagick->readImage($in_filename);
921
922 //Get the dimensions of the image we just loaded.
923 $geo = $imagick->getImageGeometry();
924 $out_filename_xdim = $geo['width'];
925 $out_filename_ydim = $geo['height'];
926
927 //Calculate target sizes. We rearrange parameters based on which is our
928 //longest side.
929 if ($out_filename_xdim >= $out_filename_ydim)
930 {
931 //Longer width (x-dimension), or square.
932 calc_thumbnail_conversion_pars
933 (
934 $out_filename_xdim,
935 $out_filename_ydim,
936 CFG_THUMBNAIL_DIMENSION_MAX,
937 $out_thumbnailname_xdim,
938 $out_thumbnailname_ydim,
939 $orig_crop_dim_x,
940 $orig_crop_dim_y,
941 $orig_crop_start_x,
942 $orig_crop_start_y
943 );
944 }
945 else
946 {
947 //Longer height (y-dimension).
948 calc_thumbnail_conversion_pars
949 (
950 $out_filename_ydim,
951 $out_filename_xdim,
952 CFG_THUMBNAIL_DIMENSION_MAX,
953 $out_thumbnailname_ydim,
954 $out_thumbnailname_xdim,
955 $orig_crop_dim_y,
956 $orig_crop_dim_x,
957 $orig_crop_start_y,
958 $orig_crop_start_x
959 );
960 }
961
962 //For debugging only, might want to know intermediate calculation results.
963 //echo "xcropdim, ycropdim, xcropstart, ycropstart: "
964 // .
965 // $orig_crop_dim_x
966 // .
967 // " "
968 // .
969 // $orig_crop_dim_y
970 // .
971 // " "
972 // .
973 // $orig_crop_start_x
974 // .
975 // " "
976 // .
977 // $orig_crop_start_y
978 // .
979 // "\n";
980
981 //Crop the original to try to preserve the aspect ratio of the thumbnail
982 //as precisely as possible.
983 $imagick->cropImage(
984 $orig_crop_dim_x,
985 $orig_crop_dim_y,
986 $orig_crop_start_x,
987 $orig_crop_start_y
988 );
989
990 //For debugging only, might want to get a look at the cropped image, to
991 //be sure nothing unexpected happens on the canvas.
992 //$imagick->writeImage($in_filename . ".cropped.jpg");
993
994 //Resize to thumbnail size.
995 if (CFG_LANCZOS_FILTER_APPLY)
996 {
997 $imagick->resizeImage($out_thumbnailname_xdim,
998 $out_thumbnailname_ydim,
999 Imagick::FILTER_LANCZOS,
1000 1);
1001 }
1002 else
1003 {
1004 $imagick->resizeImage($out_thumbnailname_xdim,
1005 $out_thumbnailname_ydim,
1006 0,
1007 1);
1008 }
1009
1010 //Create the border.
1011 $imagick->raiseImage(CFG_THUMBNAIL_BEVELED_BORDER_WIDTH,
1012 CFG_THUMBNAIL_BEVELED_BORDER_WIDTH,
1013 0,
1014 0,
1015 1);
1016
1017 //Set compression to get a smaller thumbnail written, and strip
1018 //header information. stripImage() seems to have the largest effect
1019 //on thumbnail file size, so leaving the thumbnail quality near 100%
1020 //is feasible. The jump in file size between 90% and 95% seemed to be
1021 //fairly large (40% to 50%), so I left it at 90%. My rationale is
1022 //that with the proliferation of mobile devices and cellular data,
1023 //getting the thumbnail as small as possible is more important than
1024 //the thumbnail looking perfect. If the viewer wants a perfect image,
1025 //they can view the full-sized image.
1026 $imagick->setImageCompression(Imagick::COMPRESSION_JPEG);
1027 $imagick->setImageCompressionQuality(90);
1028 $imagick->stripImage();
1029
1030 //Write the thumbnail.
1031 $imagick->writeImage($in_thumbnailname);
1032
1033 //Destroy to prevent memory leak.
1034 $imagick->clear();
1035 $imagick->destroy();
1036
1037 //All of the writing is done. Try to obtain the file sizes.
1038 $fsize = filesize($in_filename);
1039 if ($fsize !== FALSE)
1040 $out_filename_filesize = $fsize;
1041 $fsize = filesize($in_thumbnailname);
1042 if ($fsize !== FALSE)
1043 $out_thumbnailname_filesize = $fsize;
1044 }
1045 //--------------------------------------------------------------------------------
1046 //Write introductory message.
1047 hor_line_thick();
1048 echo CFG_PROGNAME . " Copyright (C) 2015 David T. Ashley\n";
1049 echo "This program comes with ABSOLUTELY NO WARRANTY; and is licensed under\n";
1050 echo "the GNU General Public License, Version 3. A copy of this license is\n";
1051 echo "provided in the source code of this program.\n";
1052 hor_line_thin();
1053 //-----------------------------------------------------------------------------
1054 //Get and emit the names of everything in the directory.
1055 $file_list = get_file_names_in_dir();
1056 if ($file_list === FALSE)
1057 {
1058 echo "List of files from PHP function scandir() is empty.\n";
1059 echo "Serious internal error, or nothing to do. Script cannot continue.\n";
1060 hor_line_thick();
1061 exit(1);
1062 }
1063 else
1064 {
1065 echo "Files in working directory (unsorted, unfiltered, "
1066 .
1067 count($file_list)
1068 .
1069 " files):\n";
1070 for ($i = 0; $i < count($file_list); $i++)
1071 echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n";
1072 }
1073 hor_line_thin();
1074 //-----------------------------------------------------------------------------
1075 //Remove the standard directory entries "." and ".." from the list, and
1076 //remove any directories.
1077 $temp_list = $file_list;
1078 unset($file_list);
1079 $n = 0;
1080 for ($i = 0; $i < count($temp_list); $i++)
1081 {
1082 //echo "Checking " . $temp_list[$i] . "\n";
1083
1084 if (strcmp($temp_list[$i], ".") == 0)
1085 {
1086 //. entry, not a file.
1087 }
1088 else if (strcmp($temp_list[$i], "..") == 0)
1089 {
1090 //.. entry, not a file.
1091 }
1092 else if (is_file($temp_list[$i]))
1093 {
1094 //This is a regular file.
1095 $file_list[] = $temp_list[$i];
1096 $n++;
1097 }
1098 }
1099
1100 if ($n == 0)
1101 $file_list = FALSE;
1102
1103 unset($n);
1104 unset($temp_list);
1105 //-----------------------------------------------------------------------------
1106 //If there is nothing to do, end the script.
1107 if ($file_list === FALSE)
1108 {
1109 echo "No files to process.\n";
1110 hor_line_thick();
1111 exit(0);
1112 }
1113 //-----------------------------------------------------------------------------
1114 //Sort the list. This is a non-event. The only rationale for sorting is that
1115 //it ensures that the same set of files will be processed in the same order,
1116 //regardless of the order provided by the underlying OS internals.
1117 sort($file_list);
1118 //-----------------------------------------------------------------------------
1119 //Emit the names we now have.
1120 echo "Files in working directory (directory entries removed, sorted, "
1121 .
1122 count($file_list)
1123 .
1124 " files):\n";
1125 for ($i = 0; $i < count($file_list); $i++)
1126 echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n";
1127 hor_line_thin();
1128
1129 //-----------------------------------------------------------------------------
1130 //For each file that is appropriate and where the thumbnail does not already
1131 //exist, up to the maximum we may do in one invocation, create the thumbnail.
1132 $i = 0;
1133 $completed = 0;
1134 while (($completed < CFG_MAX_THUMBNAILS_PER_INVOCATION) && ($i < count($file_list)))
1135 {
1136 if (is_full_sized_image_file_name($file_list[$i]))
1137 {
1138 $thumbnail_name = file_name_to_thumbnail_name($file_list[$i]);
1139
1140 if (file_exists($thumbnail_name))
1141 {
1142 echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : skipping because corresponding thumbnail exists.\n";
1143 hor_line_thin();
1144 }
1145 else
1146 {
1147 echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : creating thumbnail.\n";
1148
1149 echo "Creating thumbnail \"" .
1150 $thumbnail_name .
1151 "\" from image \"" .
1152 $file_list[$i] .
1153 "\".\n";
1154
1155 create_thumbnail($file_list[$i],
1156 $thumbnail_name,
1157 $filename_filesize,
1158 $filename_xdim,
1159 $filename_ydim,
1160 $thumbnail_filesize,
1161 $thumbnail_xdim,
1162 $thumbnail_ydim);
1163
1164 echo "Conversion complete.\n";
1165 echo " Full-sized image file size/xdim/ydim = " .
1166 $filename_filesize . "/" . $filename_xdim . "/" . $filename_ydim .
1167 ",\n";
1168 echo " Thumbnail image filesize/xdim/ydim = " .
1169 $thumbnail_filesize . "/" . $thumbnail_xdim . "/" . $thumbnail_ydim .
1170 ",\n";
1171
1172 hor_line_thin();
1173 $completed++;
1174 }
1175 }
1176 else
1177 {
1178 //Unsuitable base name. Can't use it.
1179 echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . " : skipping due to unsuitable name.\n";
1180 hor_line_thin();
1181 }
1182
1183 $i++;
1184 }
1185
1186 //Emit a message about whether the program should be run again. I am aware of
1187 //the uncovered case--where the last thumbnail was made on the last iteration
1188 //of this invocation--but I will leave it uncovered for now. All that happens
1189 //is the user runs the program unnecessarily one more time.
1190 if ($completed == 0)
1191 {
1192 echo "No thumbnails were created--this program is done creating thumbnails.\n";
1193 echo "It is not necessary to run this program again.\n";
1194 hor_line_thin();
1195 }
1196 else
1197 {
1198 echo $completed . " thumbnail(s) were created. Please run this program repeatedly again\n";
1199 echo "until no more thumbnails are created.\n";
1200 hor_line_thin();
1201 }
1202
1203 echo CFG_PROGNAME . " execution ends.\n";
1204 hor_line_thick();
1205 //--------------------------------------------------------------------------------
1206 //End of File
1207 //--------------------------------------------------------------------------------
1208 ?>

Properties

Name Value
svn:executable *

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25