Exif data is actually an extension of the TIFF file format. TIFF images consist of a number of {@link PelIfd Image File Directories} (IFDs), each containing a number of {@link PelEntry entries}. The IFDs are linked to each other --- one can get hold of the first one with the {@link getIfd()} method. To parse a TIFF image for Exif data one would do: $tiff = new PelTiff($data); $ifd0 = $tiff->getIfd(); $exif = $ifd0->getSubIfd(PelIfd::EXIF); $ifd1 = $ifd0->getNextIfd(); Should one have some image data of an unknown type, then the {@link PelTiff::isValid()} function is handy: it will quickly test if the data could be valid TIFF data. The {@link PelJpeg::isValid()} function does the same for JPEG images.
Author: Martin Geisler (mgeisler@users.sourceforge.net)
Esempio n. 1
0
        $exif->setTiff($tiff);
    } else {
        /*
         * Surprice, surprice: Exif data is really just TIFF data! So we
         * extract the PelTiff object for later use.
         */
        println('Found existing APP1 section.');
        $tiff = $exif->getTiff();
    }
} elseif (PelTiff::isValid($data)) {
    /*
     * The data was recognized as TIFF data. We prepare a PelTiff
     * object to hold it, and record in $file that the PelTiff object is
     * the top-most object (the one on which we will call getBytes).
     */
    $tiff = $file = new PelTiff();
    /* Now load the data. */
    $tiff->load($data);
} else {
    /*
     * The data was not recognized as either JPEG or TIFF data.
     * Complain loudly, dump the first 16 bytes, and exit.
     */
    println('Unrecognized image format! The first 16 bytes follow:');
    PelConvert::bytesToDump($data->getBytes(0, 16));
    exit(1);
}
/*
 * TIFF data has a tree structure much like a file system. There is a
 * root IFD (Image File Directory) which contains a number of entries
 * and maybe a link to the next IFD. The IFDs are chained together
Esempio n. 2
0
}
/*
 * 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();
        $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();
    do {
        $new = gmdate('Y:m:d-H:i:s', $time) . strchr($file, '.');
        println('Trying file name %s', $new);
        $time++;
Esempio n. 3
0
    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();
    }
}