X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Flsolesen%2Fpel%2Fexamples%2Fdirsort.php;fp=vendor%2Flsolesen%2Fpel%2Fexamples%2Fdirsort.php;h=004f70b43b23d2569523d825f2efa4b46f8dcef8;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/vendor/lsolesen/pel/examples/dirsort.php b/vendor/lsolesen/pel/examples/dirsort.php new file mode 100644 index 000000000..004f70b43 --- /dev/null +++ b/vendor/lsolesen/pel/examples/dirsort.php @@ -0,0 +1,105 @@ +#!/usr/bin/php + ...', $prog); + println('Optional arguments:'); + println(' -d turn debug output on.'); + println('Mandatory arguments:'); + println(' file ... one or more file names.'); + exit(1); +} + +/* + * We typically need lots of RAM to parse TIFF images since they tend + * to be big and uncompressed. + */ +ini_set('memory_limit', '32M'); + +foreach ($argv as $file) { + println('Reading file "%s".', $file); + $data = new PelDataWindow(file_get_contents($file)); + + if (PelJpeg::isValid($data)) { + $jpeg = new PelJpeg(); + $jpeg->load($data); + $app1 = $jpeg->getExif(); + if ($app1 == null) { + println('Skipping %s because no APP1 section was found.', $file); + continue; + } + + $tiff = $app1->getTiff(); + } elseif (PelTiff::isValid($data)) { + $tiff = new PelTiff($data); + } else { + println('Unrecognized image format! Skipping.'); + continue; + } + + $ifd0 = $tiff->getIfd(); + $entry = $ifd0->getEntry(PelTag::DATE_TIME); + + if ($entry == null) { + println('Skipping %s because no DATE_TIME tag was found.', $file); + continue; + } + + $time = $entry->getValue(); + + $new = gmdate('../Y-m/', $time) . $file; + + if (file_exists($new)) { + die('Aborting, ' . $new . ' exists!'); + } + println('mv %s %s', $file, $new); + + rename($file, $new); +}