Beispiel #1
0
 /**
  * Load and parse Exif data.
  *
  * This will populate the object with Exif data, contained as a
  * {@link PelTiff} object. This TIFF object can be accessed with
  * the {@link getTiff()} method.
  *
  * @param PelDataWindow $d
  */
 public function load(PelDataWindow $d)
 {
     Pel::debug('Parsing %d bytes of Exif data...', $d->getSize());
     /* There must be at least 6 bytes for the Exif header. */
     if ($d->getSize() < 6) {
         throw new PelInvalidDataException('Expected at least 6 bytes of Exif ' . 'data, found just %d bytes.', $d->getSize());
     }
     /* Verify the Exif header */
     if ($d->strcmp(0, self::EXIF_HEADER)) {
         $d->setWindowStart(strlen(self::EXIF_HEADER));
     } else {
         throw new PelInvalidDataException('Exif header not found.');
     }
     /* The rest of the data is TIFF data. */
     $this->tiff = new PelTiff();
     $this->tiff->load($d);
 }
Beispiel #2
0
    print "Mandatory arguments:\n";
    print "  filename  a JPEG or TIFF image.\n";
    exit(1);
}
if (!is_readable($file)) {
    printf("Unable to read %s!\n", $file);
    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');
$data = new PelDataWindow(file_get_contents($file));
if (PelJpeg::isValid($data)) {
    $img = new PelJpeg();
} elseif (PelTiff::isValid($data)) {
    $img = new PelTiff();
} else {
    print "Unrecognized image format! The first 16 bytes follow:\n";
    PelConvert::bytesToDump($data->getBytes(0, 16));
    exit(1);
}
/* Try loading the data. */
$img->load($data);
print $img;
/* Deal with any exceptions: */
if (count(Pel::getExceptions()) > 0) {
    print "\nThe following errors were encountered while loading the image:\n";
    foreach (Pel::getExceptions() as $e) {
        print "\n" . $e->__toString();
    }
}