lsolesen\pel\PelTiff::load PHP Method

load() public method

The data given will be parsed and an internal tree representation will be built. If the data cannot be parsed correctly, a {@link PelInvalidDataException} is thrown, explaining the problem.
public load ( lsolesen\pel\PelDataWindow $d )
$d lsolesen\pel\PelDataWindow
    public function load(PelDataWindow $d)
    {
        Pel::debug('Parsing %d bytes of TIFF data...', $d->getSize());
        /*
         * There must be at least 8 bytes available: 2 bytes for the byte
         * order, 2 bytes for the TIFF header, and 4 bytes for the offset
         * to the first IFD.
         */
        if ($d->getSize() < 8) {
            throw new PelInvalidDataException('Expected at least 8 bytes of TIFF ' . 'data, found just %d bytes.', $d->getSize());
        }
        /* Byte order */
        if ($d->strcmp(0, 'II')) {
            Pel::debug('Found Intel byte order');
            $d->setByteOrder(PelConvert::LITTLE_ENDIAN);
        } elseif ($d->strcmp(0, 'MM')) {
            Pel::debug('Found Motorola byte order');
            $d->setByteOrder(PelConvert::BIG_ENDIAN);
        } else {
            throw new PelInvalidDataException('Unknown byte order found in TIFF ' . 'data: 0x%2X%2X', $d->getByte(0), $d->getByte(1));
        }
        /* Verify the TIFF header */
        if ($d->getShort(2) != self::TIFF_HEADER) {
            throw new PelInvalidDataException('Missing TIFF magic value.');
        }
        /* IFD 0 offset */
        $offset = $d->getLong(4);
        Pel::debug('First IFD at offset %d.', $offset);
        if ($offset > 0) {
            /*
             * Parse the first IFD, this will automatically parse the
             * following IFDs and any sub IFDs.
             */
            $this->ifd = new PelIfd(PelIfd::IFD0);
            $this->ifd->load($d, $offset);
        }
    }

Usage Example

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