lsolesen\pel\PelTiff::isValid PHP Method

isValid() public static method

This will read just enough data from the data window to determine if the data could be a valid TIFF data. This means that the check is more like a heuristic than a rigorous check.
See also: PelJpeg::isValid()
public static isValid ( lsolesen\pel\PelDataWindow $d ) : boolean
$d lsolesen\pel\PelDataWindow the bytes that will be examined.
return boolean true if the data looks like valid TIFF data, false otherwise.
    public static function isValid(PelDataWindow $d)
    {
        /* First check that we have enough data. */
        if ($d->getSize() < 8) {
            return false;
        }
        /* Byte order */
        if ($d->strcmp(0, 'II')) {
            $d->setByteOrder(PelConvert::LITTLE_ENDIAN);
        } elseif ($d->strcmp(0, 'MM')) {
            Pel::debug('Found Motorola byte order');
            $d->setByteOrder(PelConvert::BIG_ENDIAN);
        } else {
            return false;
        }
        /* Verify the TIFF header */
        return $d->getShort(2) == self::TIFF_HEADER;
    }

Usage Example

Beispiel #1
0
    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();
        $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);