Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / lsolesen / pel / examples / dirsort.php
1 #!/usr/bin/php
2 <?php
3
4 /**
5  * PEL: PHP Exif Library.
6  * A library with support for reading and
7  * writing all Exif headers in JPEG and TIFF images using PHP.
8  *
9  * Copyright (C) 2004, 2006 Martin Geisler.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program in the file COPYING; if not, write to the
23  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24  * Boston, MA 02110-1301 USA
25  */
26
27 /* a printf() variant that appends a newline to the output. */
28 function println($args)
29 {
30     $args = func_get_args();
31     $fmt = array_shift($args);
32     vprintf($fmt . "\n", $args);
33 }
34
35 /* Make PEL speak the users language, if it is available. */
36 setlocale(LC_ALL, '');
37 require_once '../autoload.php';
38
39 use lsolesen\pel\PelDataWindow;
40 use lsolesen\pel\PelJpeg;
41 use lsolesen\pel\PelTiff;
42
43 $prog = array_shift($argv);
44 $error = false;
45
46 if (isset($argv[0]) && $argv[0] == '-d') {
47     Pel::setDebug(true);
48     array_shift($argv);
49 }
50
51 if (empty($argv)) {
52     println('Usage: %s [-d] <file> ...', $prog);
53     println('Optional arguments:');
54     println('  -d        turn debug output on.');
55     println('Mandatory arguments:');
56     println('  file ...  one or more file names.');
57     exit(1);
58 }
59
60 /*
61  * We typically need lots of RAM to parse TIFF images since they tend
62  * to be big and uncompressed.
63  */
64 ini_set('memory_limit', '32M');
65
66 foreach ($argv as $file) {
67     println('Reading file "%s".', $file);
68     $data = new PelDataWindow(file_get_contents($file));
69
70     if (PelJpeg::isValid($data)) {
71         $jpeg = new PelJpeg();
72         $jpeg->load($data);
73         $app1 = $jpeg->getExif();
74         if ($app1 == null) {
75             println('Skipping %s because no APP1 section was found.', $file);
76             continue;
77         }
78
79         $tiff = $app1->getTiff();
80     } elseif (PelTiff::isValid($data)) {
81         $tiff = new PelTiff($data);
82     } else {
83         println('Unrecognized image format! Skipping.');
84         continue;
85     }
86
87     $ifd0 = $tiff->getIfd();
88     $entry = $ifd0->getEntry(PelTag::DATE_TIME);
89
90     if ($entry == null) {
91         println('Skipping %s because no DATE_TIME tag was found.', $file);
92         continue;
93     }
94
95     $time = $entry->getValue();
96
97     $new = gmdate('../Y-m/', $time) . $file;
98
99     if (file_exists($new)) {
100         die('Aborting, ' . $new . ' exists!');
101     }
102     println('mv %s %s', $file, $new);
103
104     rename($file, $new);
105 }