Class PelJpeg

Description

Class for handling JPEG data.

The PelJpeg class defined here provides an abstraction for dealing with a JPEG file. The file will be contain a number of sections containing some content identified by a marker.

The getSection() method is used to pick out a particular section --- the EXIF information is typically stored in the APP1 section, and so if the name of the JPEG file is stored in $filename, then one would get hold of the EXIF data by saying:

  1. $jpeg = new PelJpeg();
  2. $jpeg->loadFile($filename);
  3. $app1 = $jpeg->getSection(PelJpegMarker::APP1);
  4. $tiff = $app1->getTiff();
  5. $ifd0 = $tiff->getIfd();
  6. $exif = $ifd0->getSubIfd(PelTag::EXIF_IFD_POINTER);
  7. $ifd1 = $ifd0->getNextIfd();

The $idf0 and $ifd1 variables will then be two TIFF Image File Directories, in which the data is stored under the keys found in PelTag.

Should one have some image data (in the form of a PelDataWindow) of an unknown type, then the PelJpeg::isValid() function is handy: it will quickly test if the data could be valid JPEG data. The PelTiff::isValid() function does the same for TIFF images.

Located in /PelJpeg.php (line 112)


	
			
Method Summary
 PelJpeg __construct ()
 void appendSection (PelJpegMarker $marker, PelJpegContent $content)
 string getBytes ()
 PelJpegContent getSection (PelJpegMarker $marker, int $skip)
 array getSections ()
 void insertSection (PelJpegMarker $marker, PelJpegContent $content, int $offset)
 boolean isValid (PelDataWindow $d)
 void load (PelDataWindow $d)
 void loadFile (string $filename)
 string __toString ()
Methods
Constructor __construct (line 156)

Construct a new JPEG object.

The new object will be empty, use the load() or loadFile() methods to load JPEG data from a PelDataWindow or a file, respectively.

Individual sections of JPEG content can be added with the appendSection() method --- use this method to add a PelExif object as the PelJpegMarker::APP1 section of an existing file without EXIF information:

  1. $jpeg = new PelJpeg();
  2. $jpeg->load($data);
  3. $jpeg->appendSection($exif, PelJpegMarker::APP1);

PelJpeg __construct ()
appendSection (line 293)

Add a new section.

void appendSection (PelJpegMarker $marker, PelJpegContent $content)
getBytes (line 379)

Turn this JPEG object into bytes.

The bytes returned by this method is ready to be stored in a file as a valid JPEG image.

  • return: bytes representing this JPEG object, including all its sections and their associated data.
string getBytes ()
getSection (line 346)

Get a sections corresponding to a particular marker.

This will search through the sections of this JPEG object, looking for a section identified with the specified marker. The content will then be returned. The optional argument can be used to skip over some of the sections. So if one is looking for the, say, third DHT section one would do:

  1. $dht3 = $jpeg->getSection(PelJpegMarker::DHT, 2);

whereas one can just do:

  1. $app1 = $jpeg->getSection(PelJpegMarker::APP1);

to get hold of the first (and normally only) APP1 section, which would hold the EXIF data.

  • return: the content found, or null if there is no content available.
PelJpegContent getSection (PelJpegMarker $marker, int $skip)
  • PelJpegMarker $marker: the marker identifying the section.
  • int $skip: the number of sections to be skipped. This must be a non-negative integer.
getSections (line 365)

Get all sections.

array getSections ()
insertSection (line 309)

Insert a new section.

void insertSection (PelJpegMarker $marker, PelJpegContent $content, int $offset)
  • PelJpegMarker $marker: the marker for the new section.
  • PelJpegContent $content: the content of the new section.
  • int $offset: the offset where the new section will be inserted --- use 0 to insert it at the very beginning, use 1 to insert it between sections 1 and 2, etc.
isValid (line 459)

Test data to see if it could be a valid JPEG image.

The function will only look at the first few bytes of the data, and try to determine if it could be a valid JPEG image based on those bytes. This means that the check is more like a heuristic than a rigorous check.

  • return: true if the bytes look like the beginning of a JPEG image, false otherwise.
  • static:
  • see: PelTiff::isValid()
boolean isValid (PelDataWindow $d)
load (line 176)

Load data into a JPEG object.

The data supplied will be parsed and turned into an object structure representing the image. This structure can then be manipulated and later turned back into an string of bytes.

This methods can be called at any time after a JPEG object has been constructed, also after the appendSection() has been called to append custom sections. Loading several JPEG images into one object will accumulate the sections, but there will only be one PelJpegMarker::SOS section at any given time.

void load (PelDataWindow $d)
  • PelDataWindow $d: the data that will be turned into JPEG sections.
loadFile (line 281)

Load data from a file into a JPEG object.

void loadFile (string $filename)
  • string $filename: the filename. This must be a readable file.
__toString (line 417)

Make a string representation of this JPEG object.

This is mainly usefull for debugging. It will show the structure of the image, and its sections.

  • return: debugging information about this JPEG object.
string __toString ()

SourceForge.net Logo Documentation generated on Fri, 18 Feb 2005 01:43:19 +0100 by phpDocumentor 1.3.0RC3