PHP Class lsolesen\pel\PelIfd

{@link PelTiff TIFF data} is structured as a number of Image File Directories, IFDs for short. Each IFD contains a number of {@link PelEntry entries}, some data and finally a link to the next IFD.
Author: Martin Geisler ([email protected])
Inheritance: implements IteratorAggregate, implements ArrayAccess
Datei anzeigen Open project: lsolesen/pel Class Usage Examples

Public Methods

Method Description
__construct ( $type ) Construct a new Image File Directory (IFD).
__toString ( ) : string Turn this directory into text.
addEntry ( lsolesen\pel\PelEntry $e ) Adds an entry to the directory.
addSubIfd ( PelIfd $sub ) Add a sub-IFD.
getBytes ( integer $offset, PelByteOrder $order ) Turn this directory into bytes.
getEntries ( ) : array Returns all entries contained in this IFD.
getEntry ( lsolesen\pel\PelTag $tag ) : lsolesen\pel\PelEntry Retrieve an entry.
getIterator ( ) : Iterator Return an iterator for all entries contained in this IFD.
getName ( ) : string Get the name of this directory.
getNextIfd ( ) : PelIfd Return the IFD pointed to by this directory.
getSubIfd ( integer $type ) : PelIfd Return a sub IFD.
getSubIfds ( ) : array Get all sub IFDs.
getThumbnailData ( ) : string Returns available thumbnail data.
getType ( ) : integer Get the type of this directory.
getTypeName ( integer $type ) : string Get the name of an IFD type.
getValidTags ( ) : array Returns a list of valid tags for this IFD.
isLastIfd ( ) : boolean Check if this is the last IFD.
isValidTag ( lsolesen\pel\PelTag $tag ) : boolean Is a given tag valid for this IFD?
load ( lsolesen\pel\PelDataWindow $d, integer $offset ) Load data into a Image File Directory (IFD).
newEntryFromData ( lsolesen\pel\PelTag $tag, lsolesen\pel\PelFormat $format, integer $components, lsolesen\pel\PelDataWindow $data ) : lsolesen\pel\PelEntry Make a new entry from a bunch of bytes.
offsetExists ( lsolesen\pel\PelTag $tag ) : boolean Does a given tag exist in this IFD?
offsetGet ( lsolesen\pel\PelTag $tag ) : lsolesen\pel\PelEntry Retrieve a given tag from this IFD.
offsetSet ( lsolesen\pel\PelTag $tag, lsolesen\pel\PelEntry $e ) Set or update a given tag in this IFD.
offsetUnset ( lsolesen\pel\PelTag $tag ) Unset a given tag in this IFD.
setNextIfd ( PelIfd $i ) Make this directory point to a new directory.
setThumbnail ( lsolesen\pel\PelDataWindow $d ) Set thumbnail data.

Private Methods

Method Description
safeSetThumbnail ( lsolesen\pel\PelDataWindow $d, integer $offset, integer $length ) Extract thumbnail data safely.

Method Details

__construct() public method

The IFD will be empty, use the {@link addEntry()} method to add an {@link PelEntry}. Use the {@link setNext()} method to link this IFD to another.
public __construct ( $type )

__toString() public method

Turn this directory into text.
public __toString ( ) : string
return string information about the directory, mainly for debugging.

addEntry() public method

Adds an entry to the directory.
public addEntry ( lsolesen\pel\PelEntry $e )
$e lsolesen\pel\PelEntry the entry that will be added. If the entry is not valid in this IFD (as per {@link isValidTag()}) an {@link PelInvalidDataException} is thrown.

addSubIfd() public method

Any previous sub-IFD of the same type will be overwritten.
public addSubIfd ( PelIfd $sub )
$sub PelIfd the sub IFD. The type of must be one of {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}.

getBytes() public method

This directory will be turned into a byte string, with the specified byte order. The offsets will be calculated from the offset given.
public getBytes ( integer $offset, PelByteOrder $order )
$offset integer the offset of the first byte of this directory.
$order PelByteOrder the byte order that should be used when turning integers into bytes. This should be one of {@link PelConvert::LITTLE_ENDIAN} and {@link PelConvert::BIG_ENDIAN}.

getEntries() public method

Returns all entries contained in this IFD.
See also: getEntry
See also: getIterator
public getEntries ( ) : array
return array an array of {@link PelEntry} objects, or rather descendant classes. The array has {@link PelTag}s as keys and the entries as values.

getEntry() public method

Retrieve an entry.
public getEntry ( lsolesen\pel\PelTag $tag ) : lsolesen\pel\PelEntry
$tag lsolesen\pel\PelTag the tag identifying the entry.
return lsolesen\pel\PelEntry the entry associated with the tag, or null if no such entry exists.

getIterator() public method

Used with foreach as in foreach ($ifd as $tag => $entry) { $tag is now a PelTag and $entry is a PelEntry object. }
public getIterator ( ) : Iterator
return Iterator an iterator using the {@link PelTag tags} as keys and the entries as values.

getName() public method

Get the name of this directory.
public getName ( ) : string
return string the name of this directory.

getNextIfd() public method

Return the IFD pointed to by this directory.
public getNextIfd ( ) : PelIfd
return PelIfd the next IFD, following this IFD. If this is the last IFD, null is returned.

getSubIfd() public method

Return a sub IFD.
public getSubIfd ( integer $type ) : PelIfd
$type integer the type of the sub IFD. This must be one of {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}.
return PelIfd the IFD associated with the type, or null if that sub IFD does not exist.

getSubIfds() public method

Get all sub IFDs.
public getSubIfds ( ) : array
return array an associative array with (IFD-type, {@link PelIfd}) pairs.

getThumbnailData() public method

Returns available thumbnail data.
public getThumbnailData ( ) : string
return string the bytes in the thumbnail, if any. If the IFD does not contain any thumbnail data, the empty string is returned.

getType() public method

Get the type of this directory.
public getType ( ) : integer
return integer of {@link PelIfd::IFD0}, {@link PelIfd::IFD1}, {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}.

getTypeName() public static method

Get the name of an IFD type.
public static getTypeName ( integer $type ) : string
$type integer one of {@link PelIfd::IFD0}, {@link PelIfd::IFD1}, {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}.
return string the name of type.

getValidTags() public method

Returns a list of valid tags for this IFD.
public getValidTags ( ) : array
return array an array of {@link PelTag}s which are valid for this IFD.

isLastIfd() public method

Check if this is the last IFD.
public isLastIfd ( ) : boolean
return boolean true if there are no following IFD, false otherwise.

isValidTag() public method

Different types of IFDs can contain different kinds of tags --- the {@link IFD0} type, for example, cannot contain a {@link PelTag::GPS_LONGITUDE} tag. A special exception is tags with values above 0xF000. They are treated as private tags and will be allowed everywhere (use this for testing or for implementing your own types of tags).
See also: getValidTags()
public isValidTag ( lsolesen\pel\PelTag $tag ) : boolean
$tag lsolesen\pel\PelTag the tag.
return boolean true if the tag is considered valid in this IFD, false otherwise.

load() public method

Load data into a Image File Directory (IFD).
public load ( lsolesen\pel\PelDataWindow $d, integer $offset )
$d lsolesen\pel\PelDataWindow the data window that will provide the data.
$offset integer the offset within the window where the directory will be found.

newEntryFromData() public method

This method will create the proper subclass of {@link PelEntry} corresponding to the {@link PelTag} and {@link PelFormat} given. The entry will be initialized with the data given. Please note that the data you pass to this method should come from an image, that is, it should be raw bytes. If instead you want to create an entry for holding, say, an short integer, then create a {@link PelEntryShort} object directly and load the data into it. A {@link PelUnexpectedFormatException} is thrown if a mismatch is discovered between the tag and format, and likewise a {@link PelWrongComponentCountException} is thrown if the number of components does not match the requirements of the tag. The requirements for a given tag (if any) can be found in the documentation for {@link PelTag}.
public newEntryFromData ( lsolesen\pel\PelTag $tag, lsolesen\pel\PelFormat $format, integer $components, lsolesen\pel\PelDataWindow $data ) : lsolesen\pel\PelEntry
$tag lsolesen\pel\PelTag the tag of the entry.
$format lsolesen\pel\PelFormat the format of the entry.
$components integer the components in the entry.
$data lsolesen\pel\PelDataWindow the data which will be used to construct the entry.
return lsolesen\pel\PelEntry a newly created entry, holding the data given.

offsetExists() public method

This methods is part of the ArrayAccess SPL interface for overriding array access of objects, it allows you to check for existance of an entry in the IFD: if (isset($ifd[PelTag::FNUMBER])) ... do something with the F-number.
public offsetExists ( lsolesen\pel\PelTag $tag ) : boolean
$tag lsolesen\pel\PelTag the offset to check.
return boolean whether the tag exists.

offsetGet() public method

This methods is part of the ArrayAccess SPL interface for overriding array access of objects, it allows you to read entries from the IFD the same was as for an array: $entry = $ifd[PelTag::FNUMBER];
public offsetGet ( lsolesen\pel\PelTag $tag ) : lsolesen\pel\PelEntry
$tag lsolesen\pel\PelTag the tag to return. It is an error to ask for a tag which is not in the IFD, just like asking for a non-existant array entry.
return lsolesen\pel\PelEntry the entry.

offsetSet() public method

This methods is part of the ArrayAccess SPL interface for overriding array access of objects, it allows you to add new entries or replace esisting entries by doing: $ifd[PelTag::EXPOSURE_BIAS_VALUE] = $entry; Note that the actual array index passed is ignored! Instead the {@link PelTag} from the entry is used.
public offsetSet ( lsolesen\pel\PelTag $tag, lsolesen\pel\PelEntry $e )
$tag lsolesen\pel\PelTag the offset to update.
$e lsolesen\pel\PelEntry the new value.

offsetUnset() public method

This methods is part of the ArrayAccess SPL interface for overriding array access of objects, it allows you to delete entries in the IFD by doing: unset($ifd[PelTag::EXPOSURE_BIAS_VALUE])
public offsetUnset ( lsolesen\pel\PelTag $tag )
$tag lsolesen\pel\PelTag the offset to delete.

setNextIfd() public method

Make this directory point to a new directory.
public setNextIfd ( PelIfd $i )
$i PelIfd the IFD that this directory will point to.

setThumbnail() public method

Use this to embed an arbitrary JPEG image within this IFD. The data will be checked to ensure that it has a proper {@link PelJpegMarker::EOI} at the end. If not, then the length is adjusted until one if found. An {@link PelIfdException} might be thrown (depending on {@link Pel::$strict}) this case.
public setThumbnail ( lsolesen\pel\PelDataWindow $d )
$d lsolesen\pel\PelDataWindow the thumbnail data.