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, 2005, 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 /* Make PEL speak the users language, if it is available. */
28 setlocale(LC_ALL, '');
30 require_once '../autoload.php';
31 use lsolesen\pel\PelDataWindow;
32 use lsolesen\pel\PelJpeg;
33 use lsolesen\pel\PelTiff;
35 $prog = array_shift($argv);
38 while (! empty($argv)) {
44 Pel::setStrictParsing(true);
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");
63 if (! is_readable($file)) {
64 printf("Unable to read %s!\n", $file);
69 * We typically need lots of RAM to parse TIFF images since they tend
70 * to be big and uncompressed.
72 ini_set('memory_limit', '32M');
74 $data = new PelDataWindow(file_get_contents($file));
76 if (PelJpeg::isValid($data)) {
78 } elseif (PelTiff::isValid($data)) {
81 print("Unrecognized image format! The first 16 bytes follow:\n");
82 PelConvert::bytesToDump($data->getBytes(0, 16));
86 /* Try loading the data. */
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());