Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / lsolesen / pel / examples / dump-image.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, 2005, 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 /* Make PEL speak the users language, if it is available. */
28 setlocale(LC_ALL, '');
29
30 require_once '../autoload.php';
31 use lsolesen\pel\PelDataWindow;
32 use lsolesen\pel\PelJpeg;
33 use lsolesen\pel\PelTiff;
34
35 $prog = array_shift($argv);
36 $file = '';
37
38 while (! empty($argv)) {
39     switch ($argv[0]) {
40         case '-d':
41             Pel::setDebug(true);
42             break;
43         case '-s':
44             Pel::setStrictParsing(true);
45             break;
46         default:
47             $file = $argv[0];
48             break;
49     }
50     array_shift($argv);
51 }
52
53 if (empty($file)) {
54     printf("Usage: %s [-d] [-s] <filename>\n", $prog);
55     print("Optional arguments:\n");
56     print("  -d        turn debug output on.\n");
57     print("  -s        turn strict parsing on (halt on errors).\n");
58     print("Mandatory arguments:\n");
59     print("  filename  a JPEG or TIFF image.\n");
60     exit(1);
61 }
62
63 if (! is_readable($file)) {
64     printf("Unable to read %s!\n", $file);
65     exit(1);
66 }
67
68 /*
69  * We typically need lots of RAM to parse TIFF images since they tend
70  * to be big and uncompressed.
71  */
72 ini_set('memory_limit', '32M');
73
74 $data = new PelDataWindow(file_get_contents($file));
75
76 if (PelJpeg::isValid($data)) {
77     $img = new PelJpeg();
78 } elseif (PelTiff::isValid($data)) {
79     $img = new PelTiff();
80 } else {
81     print("Unrecognized image format! The first 16 bytes follow:\n");
82     PelConvert::bytesToDump($data->getBytes(0, 16));
83     exit(1);
84 }
85
86 /* Try loading the data. */
87 $img->load($data);
88
89 print($img);
90
91 /* Deal with any exceptions: */
92 if (count(Pel::getExceptions()) > 0) {
93     print("\nThe following errors were encountered while loading the image:\n");
94     foreach (Pel::getExceptions() as $e) {
95         print("\n" . $e->__toString());
96     }
97 }