summaryrefslogtreecommitdiff
path: root/includes/media/JpegMetadataExtractor.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/media/JpegMetadataExtractor.php')
-rw-r--r--includes/media/JpegMetadataExtractor.php79
1 files changed, 43 insertions, 36 deletions
diff --git a/includes/media/JpegMetadataExtractor.php b/includes/media/JpegMetadataExtractor.php
index 8d7e43b9..c7030eba 100644
--- a/includes/media/JpegMetadataExtractor.php
+++ b/includes/media/JpegMetadataExtractor.php
@@ -25,7 +25,7 @@
* Class for reading jpegs and extracting metadata.
* see also BitmapMetadataHandler.
*
- * Based somewhat on GIFMetadataExtrator.
+ * Based somewhat on GIFMetadataExtractor.
*
* @ingroup Media
*/
@@ -37,17 +37,17 @@ class JpegMetadataExtractor {
// that many segments. Your average file has about 10.
/** Function to extract metadata segments of interest from jpeg files
- * based on GIFMetadataExtractor.
- *
- * we can almost use getimagesize to do this
- * but gis doesn't support having multiple app1 segments
- * and those can't extract xmp on files containing both exif and xmp data
- *
- * @param String $filename name of jpeg file
- * @return Array of interesting segments.
- * @throws MWException if given invalid file.
- */
- static function segmentSplitter ( $filename ) {
+ * based on GIFMetadataExtractor.
+ *
+ * we can almost use getimagesize to do this
+ * but gis doesn't support having multiple app1 segments
+ * and those can't extract xmp on files containing both exif and xmp data
+ *
+ * @param string $filename name of jpeg file
+ * @return Array of interesting segments.
+ * @throws MWException if given invalid file.
+ */
+ static function segmentSplitter( $filename ) {
$showXMP = function_exists( 'xml_parser_create_ns' );
$segmentCount = 0;
@@ -87,7 +87,7 @@ class JpegMetadataExtractor {
}
$buffer = fread( $fh, 1 );
- while( $buffer === "\xFF" && !feof( $fh ) ) {
+ while ( $buffer === "\xFF" && !feof( $fh ) ) {
// Skip through any 0xFF padding bytes.
$buffer = fread( $fh, 1 );
}
@@ -111,7 +111,7 @@ class JpegMetadataExtractor {
if ( $com === $oldCom ) {
$segments["COM"][] = $oldCom;
} else {
- wfDebug( __METHOD__ . ' Ignoring JPEG comment as is garbage.' );
+ wfDebug( __METHOD__ . " Ignoring JPEG comment as is garbage.\n" );
}
} elseif ( $buffer === "\xE1" ) {
@@ -129,7 +129,7 @@ class JpegMetadataExtractor {
// whatever...
$segments["XMP"] = substr( $temp, 29 );
wfDebug( __METHOD__ . ' Found XMP section with wrong app identifier '
- . "Using anyways.\n" );
+ . "Using anyways.\n" );
} elseif ( substr( $temp, 0, 6 ) === "Exif\0\0" ) {
// Just need to find out what the byte order is.
// because php's exif plugin sucks...
@@ -140,7 +140,7 @@ class JpegMetadataExtractor {
} elseif ( $byteOrderMarker === 'II' ) {
$segments['byteOrder'] = 'LE';
} else {
- wfDebug( __METHOD__ . ' Invalid byte ordering?!' );
+ wfDebug( __METHOD__ . " Invalid byte ordering?!\n" );
}
}
} elseif ( $buffer === "\xED" ) {
@@ -155,7 +155,9 @@ class JpegMetadataExtractor {
} else {
// segment we don't care about, so skip
$size = wfUnpack( "nint", fread( $fh, 2 ), 2 );
- if ( $size['int'] <= 2 ) throw new MWException( "invalid marker size in jpeg" );
+ if ( $size['int'] <= 2 ) {
+ throw new MWException( "invalid marker size in jpeg" );
+ }
fseek( $fh, $size['int'] - 2, SEEK_CUR );
}
@@ -165,10 +167,11 @@ class JpegMetadataExtractor {
}
/**
- * Helper function for jpegSegmentSplitter
- * @param &$fh FileHandle for jpeg file
- * @return string data content of segment.
- */
+ * Helper function for jpegSegmentSplitter
+ * @param &$fh FileHandle for jpeg file
+ * @throws MWException
+ * @return string data content of segment.
+ */
private static function jpegExtractMarker( &$fh ) {
$size = wfUnpack( "nint", fread( $fh, 2 ), 2 );
if ( $size['int'] <= 2 ) {
@@ -182,19 +185,19 @@ class JpegMetadataExtractor {
}
/**
- * This reads the photoshop image resource.
- * Currently it only compares the iptc/iim hash
- * with the stored hash, which is used to determine the precedence
- * of the iptc data. In future it may extract some other info, like
- * url of copyright license.
- *
- * This should generally be called by BitmapMetadataHandler::doApp13()
- *
- * @param String $app13 photoshop psir app13 block from jpg.
- * @throws MWException (It gets caught next level up though)
- * @return String if the iptc hash is good or not.
- */
- public static function doPSIR ( $app13 ) {
+ * This reads the photoshop image resource.
+ * Currently it only compares the iptc/iim hash
+ * with the stored hash, which is used to determine the precedence
+ * of the iptc data. In future it may extract some other info, like
+ * url of copyright license.
+ *
+ * This should generally be called by BitmapMetadataHandler::doApp13()
+ *
+ * @param string $app13 photoshop psir app13 block from jpg.
+ * @throws MWException (It gets caught next level up though)
+ * @return String if the iptc hash is good or not.
+ */
+ public static function doPSIR( $app13 ) {
if ( !$app13 ) {
throw new MWException( "No App13 segment given" );
}
@@ -242,7 +245,9 @@ class JpegMetadataExtractor {
// PHP can take issue with very large unsigned ints and make them negative.
// Which should never ever happen, as this has to be inside a segment
// which is limited to a 16 bit number.
- if ( $lenData['len'] < 0 ) throw new MWException( "Too big PSIR (" . $lenData['len'] . ')' );
+ if ( $lenData['len'] < 0 ) {
+ throw new MWException( "Too big PSIR (" . $lenData['len'] . ')' );
+ }
$offset += 4; // 4bytes length field;
@@ -266,7 +271,9 @@ class JpegMetadataExtractor {
// if odd, add 1 to length to account for
// null pad byte.
- if ( $lenData['len'] % 2 == 1 ) $lenData['len']++;
+ if ( $lenData['len'] % 2 == 1 ) {
+ $lenData['len']++;
+ }
$offset += $lenData['len'];
}