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.
9 * Copyright (C) 2004, 2006 Martin Geisler.
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.
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.
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
27 /* a printf() variant that appends a newline to the output. */
28 function println($args)
30 $args = func_get_args();
31 $fmt = array_shift($args);
32 vprintf($fmt . "\n", $args);
35 /* Make PEL speak the users language, if it is available. */
36 setlocale(LC_ALL, '');
37 require_once '../autoload.php';
39 use lsolesen\pel\PelDataWindow;
40 use lsolesen\pel\PelJpeg;
41 use lsolesen\pel\PelTiff;
43 $prog = array_shift($argv);
46 if (isset($argv[0]) && $argv[0] == '-d') {
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.');
61 * We typically need lots of RAM to parse TIFF images since they tend
62 * to be big and uncompressed.
64 ini_set('memory_limit', '32M');
66 foreach ($argv as $file) {
67 println('Reading file "%s".', $file);
68 $data = new PelDataWindow(file_get_contents($file));
70 if (PelJpeg::isValid($data)) {
71 $jpeg = new PelJpeg();
73 $app1 = $jpeg->getExif();
75 println('Skipping %s because no APP1 section was found.', $file);
79 $tiff = $app1->getTiff();
80 } elseif (PelTiff::isValid($data)) {
81 $tiff = new PelTiff($data);
83 println('Unrecognized image format! Skipping.');
87 $ifd0 = $tiff->getIfd();
88 $entry = $ifd0->getEntry(PelTag::DATE_TIME);
91 println('Skipping %s because no DATE_TIME tag was found.', $file);
95 $time = $entry->getValue();
97 $new = gmdate('../Y-m/', $time) . $file;
99 if (file_exists($new)) {
100 die('Aborting, ' . $new . ' exists!');
102 println('mv %s %s', $file, $new);