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 one would get hold of it by saying:

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

Should one have some image data 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 104)


	
			
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 148)

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 285)

Add a new section.

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

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 338)

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 357)

Get all sections.

array getSections ()
insertSection (line 301)

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 451)

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 168)

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 273)

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 409)

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 Wed, 21 Jul 2004 19:13:12 +0200 by phpDocumentor 1.3.0RC3