MediaWiki REL1_34
Exif Class Reference

Class to extract and validate Exif data from jpeg (and possibly tiff) files. More...

Public Member Functions

 __construct ( $file, $byteOrder='')
 
 collapseData ()
 Collapse some fields together.
 
 getData ()
 #-
 
 getFilteredData ()
 Get $this->mFilteredExifData.
 
 makeFilteredData ()
 Make $this->mFilteredExifData.
 

Static Public Member Functions

static version ()
 #-
 

Public Attributes

const ASCII = 2
 An 8-bit byte containing one 7-bit ASCII code.
 
const BYTE = 1
 An 8-bit (1-byte) unsigned integer.
 
const IGNORE = -1
 A fake value for things we don't want or don't support.
 
const LONG = 4
 A 32-bit (4-byte) unsigned integer.
 
const RATIONAL = 5
 Two LONGs.
 
const SHORT = 3
 A 16-bit (2-byte) unsigned integer.
 
const SHORT_OR_LONG = 6
 A 16-bit (2-byte) or 32-bit (4-byte) unsigned integer.
 
const SLONG = 9
 A 32-bit (4-byte) signed integer (2's complement notation),.
 
const SRATIONAL = 10
 Two SLONGs.
 
const UNDEFINED = 7
 An 8-bit byte that can take any value depending on the field definition.
 

Private Member Functions

 charCodeString ( $prop)
 Do userComment tags and similar.
 
 debug ( $in, $fname, $action=null)
 Convenience function for debugging output.
 
 debugFile ( $fname, $io)
 Convenience function for debugging output.
 
 exifGPStoNumber ( $prop)
 Convert gps in exif form to a single floating point number for example 10 degress 2040` S -> -10.34444.
 
 exifPropToOrd ( $prop)
 Convert an Exif::UNDEFINED from a raw binary string to its value.
 
 isASCII ( $in)
 
 isByte ( $in)
 Validates if a tag value is of the type it should be according to the Exif spec.
 
 isLong ( $in)
 
 isRational ( $in)
 
 isShort ( $in)
 
 isSlong ( $in)
 
 isSrational ( $in)
 
 isUndefined ( $in)
 
 validate ( $section, $tag, $val, $recursive=false)
 #-
 

Private Attributes

string $basename
 The basename of the file being processed.
 
string $byteOrder
 The byte order of the file.
 
string $file
 The file being processed.
 
string $log = false
 The private log to log to, e.g.
 
array $mExifTags
 Exif tags grouped by category, the tagname itself is the key and the type is the value, in the case of more than one possible value type they are separated by commas.
 
array $mFilteredExifData
 A Filtered version of $mRawExifData that has been pruned of invalid tags and tags that contain content they shouldn't contain according to the Exif specification.
 
array $mRawExifData
 The raw Exif data returned by exif_read_data()
 

Detailed Description

Class to extract and validate Exif data from jpeg (and possibly tiff) files.

Definition at line 32 of file Exif.php.

Constructor & Destructor Documentation

◆ __construct()

Exif::__construct (   $file,
  $byteOrder = '' 
)
Parameters
string$fileFilename.
string$byteOrderType of byte ordering either 'BE' (Big Endian) or 'LE' (Little Endian). Default ''.
Exceptions
MWException
Todo:
FIXME: The following are broke: SubjectArea. Need to test the more obscure tags. DigitalZoomRatio = 0/0 is rejected. need to determine if that's valid. Possibly should treat 0/0 = 0. need to read exif spec on that.

Definition at line 108 of file Exif.php.

References $byteOrder, $file, ASCII, collapseData(), debugFile(), IGNORE, makeFilteredData(), RATIONAL, SHORT, SHORT_OR_LONG, SRATIONAL, UNDEFINED, version(), wfBaseName(), and wfWarn().

Member Function Documentation

◆ charCodeString()

Exif::charCodeString (   $prop)
private

Do userComment tags and similar.

See pg. 34 of exif standard. basically first 8 bytes is charset, rest is value. This has not been tested on any shift-JIS strings.

Parameters
string$propProp name

Definition at line 444 of file Exif.php.

References $byteOrder, and debug().

Referenced by collapseData().

◆ collapseData()

Exif::collapseData ( )

Collapse some fields together.

This converts some fields from exif form, to a more friendly form. For example GPS latitude to a single number.

The rationale behind this is that we're storing data, not presenting to the user For example a longitude is a single number describing how far away you are from the prime meridian. Well it might be nice to split it up into minutes and seconds for the user, it doesn't really make sense to split a single number into 4 parts for storage. (degrees, minutes, second, direction vs single floating point number).

Other things this might do (not really sure if they make sense or not): Dates -> mediawiki date format. convert values that can be in different units to be in one standardized unit.

As an alternative approach, some of this could be done in the validate phase if we make up our own types like Exif::DATE.

Definition at line 362 of file Exif.php.

References charCodeString(), exifGPStoNumber(), and exifPropToOrd().

Referenced by __construct().

◆ debug()

Exif::debug (   $in,
  $fname,
  $action = null 
)
private

Convenience function for debugging output.

Parameters
mixed$inArrays will be processed with print_r().
string$fnameFunction name to log.
string | bool | null$actionDefault null.

Definition at line 820 of file Exif.php.

References $type, and wfDebugLog().

Referenced by charCodeString(), isASCII(), isByte(), isLong(), isRational(), isShort(), isSlong(), isSrational(), isUndefined(), makeFilteredData(), and validate().

◆ debugFile()

Exif::debugFile (   $fname,
  $io 
)
private

Convenience function for debugging output.

Parameters
string$fnameThe name of the function calling this function
bool$ioSpecify whether we're beginning or ending

Definition at line 847 of file Exif.php.

References wfDebugLog().

Referenced by __construct().

◆ exifGPStoNumber()

Exif::exifGPStoNumber (   $prop)
private

Convert gps in exif form to a single floating point number for example 10 degress 2040` S -> -10.34444.

Parameters
string$propA GPS coordinate exif tag name (like GPSLongitude)

Definition at line 515 of file Exif.php.

References $res.

Referenced by collapseData().

◆ exifPropToOrd()

Exif::exifPropToOrd (   $prop)
private

Convert an Exif::UNDEFINED from a raw binary string to its value.

This is sometimes needed depending on the type of UNDEFINED field

Parameters
string$propName of property

Definition at line 504 of file Exif.php.

Referenced by collapseData().

◆ getData()

Exif::getData ( )

#-

#+

Returns
array Get $this->mRawExifData
array

Definition at line 556 of file Exif.php.

References $mRawExifData.

◆ getFilteredData()

Exif::getFilteredData ( )

Get $this->mFilteredExifData.

Returns
array

Definition at line 564 of file Exif.php.

References $mFilteredExifData.

◆ isASCII()

Exif::isASCII (   $in)
private
Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 608 of file Exif.php.

References debug().

Referenced by validate().

◆ isByte()

Exif::isByte (   $in)
private

Validates if a tag value is of the type it should be according to the Exif spec.

Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 592 of file Exif.php.

References debug().

Referenced by validate().

◆ isLong()

Exif::isLong (   $in)
private
Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 648 of file Exif.php.

References debug().

Referenced by isRational(), isSlong(), and validate().

◆ isRational()

Exif::isRational (   $in)
private
Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 664 of file Exif.php.

References debug(), and isLong().

Referenced by validate().

◆ isShort()

Exif::isShort (   $in)
private
Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 632 of file Exif.php.

References debug().

Referenced by validate().

◆ isSlong()

Exif::isSlong (   $in)
private
Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 693 of file Exif.php.

References debug(), and isLong().

Referenced by isSrational(), and validate().

◆ isSrational()

Exif::isSrational (   $in)
private
Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 709 of file Exif.php.

References debug(), and isSlong().

Referenced by validate().

◆ isUndefined()

Exif::isUndefined (   $in)
private
Parameters
mixed$inThe input value to check
Returns
bool

Definition at line 683 of file Exif.php.

References debug().

Referenced by validate().

◆ makeFilteredData()

Exif::makeFilteredData ( )

Make $this->mFilteredExifData.

Definition at line 316 of file Exif.php.

References debug(), and validate().

Referenced by __construct().

◆ validate()

Exif::validate (   $section,
  $tag,
  $val,
  $recursive = false 
)
private

#-

Validates if a tag has a legal value according to the Exif spec

Parameters
string$sectionSection where tag is located.
string$tagThe tag to check.
mixed$valThe value of the tag.
bool$recursiveTrue if called recursively for array types.
Returns
bool

Definition at line 735 of file Exif.php.

References $debug, ASCII, BYTE, debug(), IGNORE, isASCII(), isByte(), isLong(), isRational(), isShort(), isSlong(), isSrational(), isUndefined(), LONG, RATIONAL, SHORT, SHORT_OR_LONG, SLONG, SRATIONAL, UNDEFINED, and validate().

Referenced by makeFilteredData(), and validate().

◆ version()

static Exif::version ( )
static

#-

The version of the output format

Before the actual metadata information is saved in the database we strip some of it since we don't want to save things like thumbnails which usually accompany Exif data. This value gets saved in the database along with the actual Exif data, and if the version in the database doesn't equal the value returned by this function the Exif data is regenerated.

Returns
int

Definition at line 582 of file Exif.php.

Referenced by __construct(), JpegHandler\getMetadata(), TiffHandler\getMetadata(), ExifBitmapHandler\isMetadataValid(), and BitmapMetadataHandler\Tiff().

Member Data Documentation

◆ $basename

string Exif::$basename
private

The basename of the file being processed.

Definition at line 88 of file Exif.php.

◆ $byteOrder

string Exif::$byteOrder
private

The byte order of the file.

Needed because php's extension doesn't fully process some obscure props.

Definition at line 96 of file Exif.php.

Referenced by __construct(), and charCodeString().

◆ $file

string Exif::$file
private

The file being processed.

Definition at line 85 of file Exif.php.

Referenced by __construct().

◆ $log

string Exif::$log = false
private

The private log to log to, e.g.

'exif'

Definition at line 91 of file Exif.php.

◆ $mExifTags

array Exif::$mExifTags
private

Exif tags grouped by category, the tagname itself is the key and the type is the value, in the case of more than one possible value type they are separated by commas.

Definition at line 73 of file Exif.php.

◆ $mFilteredExifData

array Exif::$mFilteredExifData
private

A Filtered version of $mRawExifData that has been pruned of invalid tags and tags that contain content they shouldn't contain according to the Exif specification.

Definition at line 82 of file Exif.php.

Referenced by getFilteredData().

◆ $mRawExifData

array Exif::$mRawExifData
private

The raw Exif data returned by exif_read_data()

Definition at line 76 of file Exif.php.

Referenced by getData().

◆ ASCII

const Exif::ASCII = 2

An 8-bit byte containing one 7-bit ASCII code.

The final byte is terminated with NULL.

Definition at line 39 of file Exif.php.

Referenced by __construct(), and validate().

◆ BYTE

const Exif::BYTE = 1

An 8-bit (1-byte) unsigned integer.

Definition at line 34 of file Exif.php.

Referenced by validate().

◆ IGNORE

const Exif::IGNORE = -1

A fake value for things we don't want or don't support.

Definition at line 67 of file Exif.php.

Referenced by __construct(), and validate().

◆ LONG

const Exif::LONG = 4

A 32-bit (4-byte) unsigned integer.

Definition at line 45 of file Exif.php.

Referenced by validate().

◆ RATIONAL

const Exif::RATIONAL = 5

Two LONGs.

The first LONG is the numerator and the second LONG expresses the denominator

Definition at line 50 of file Exif.php.

Referenced by __construct(), and validate().

◆ SHORT

const Exif::SHORT = 3

A 16-bit (2-byte) unsigned integer.

Definition at line 42 of file Exif.php.

Referenced by __construct(), and validate().

◆ SHORT_OR_LONG

const Exif::SHORT_OR_LONG = 6

A 16-bit (2-byte) or 32-bit (4-byte) unsigned integer.

Definition at line 53 of file Exif.php.

Referenced by __construct(), and validate().

◆ SLONG

const Exif::SLONG = 9

A 32-bit (4-byte) signed integer (2's complement notation),.

Definition at line 59 of file Exif.php.

Referenced by validate().

◆ SRATIONAL

const Exif::SRATIONAL = 10

Two SLONGs.

The first SLONG is the numerator and the second SLONG is the denominator.

Definition at line 64 of file Exif.php.

Referenced by __construct(), and validate().

◆ UNDEFINED

const Exif::UNDEFINED = 7

An 8-bit byte that can take any value depending on the field definition.

Definition at line 56 of file Exif.php.

Referenced by __construct(), and validate().


The documentation for this class was generated from the following file: