40 20 =>
array(
'other' ),
41 40 =>
array(
'native' ),
42 60 =>
array(
'iptc-good-hash',
'iptc-no-hash' ),
43 70 =>
array(
'xmp-deprecated' ),
44 80 =>
array(
'xmp-general' ),
45 90 =>
array(
'xmp-exif' ),
46 100 =>
array(
'iptc-bad-hash' ),
47 120 =>
array(
'exif' ),
61 private function doApp13( $app13 ) {
68 wfDebug(
"Error parsing iptc data of file: " .
$e->getMessage() .
"\n" );
69 $this->iptcType =
'iptc-no-hash';
86 function getExif( $filename, $byteOrder ) {
88 if ( file_exists( $filename ) && $wgShowEXIF ) {
89 $exif =
new Exif( $filename, $byteOrder );
90 $data = $exif->getFilteredData();
104 if ( isset( $this->metadata[
$type] ) ) {
106 $metaArray = $metaArray + $this->metadata[
$type];
109 $this->metadata[
$type] = $metaArray;
125 krsort( $this->metaPriority );
126 foreach ( $this->metaPriority
as $pri ) {
128 if ( isset( $this->metadata[
$type] ) ) {
131 foreach ( $this->metadata[
$type]
as $itemName => $item ) {
132 if ( is_array( $item ) && isset( $item[
'_type'] ) && $item[
'_type'] ===
'lang' ) {
133 if ( isset( $temp[$itemName] ) && !is_array( $temp[$itemName] ) ) {
134 $default = $temp[$itemName];
135 $temp[$itemName] = $item;
136 $temp[$itemName][
'x-default'] = $default;
137 unset( $this->metadata[
$type][$itemName] );
142 $temp = $temp + $this->metadata[
$type];
156 static function Jpeg( $filename ) {
157 $showXMP = function_exists(
'xml_parser_create_ns' );
161 if ( isset( $seg[
'COM'] ) && isset( $seg[
'COM'][0] ) ) {
162 $meta->addMetadata(
array(
'JPEGFileComment' => $seg[
'COM'] ),
'native' );
164 if ( isset( $seg[
'PSIR'] ) && count( $seg[
'PSIR'] ) > 0 ) {
165 foreach ( $seg[
'PSIR']
as $curPSIRValue ) {
166 $meta->doApp13( $curPSIRValue );
169 if ( isset( $seg[
'XMP'] ) && $showXMP ) {
171 $xmp->parse( $seg[
'XMP'] );
172 foreach ( $seg[
'XMP_ext']
as $xmpExt ) {
176 $xmp->parseExtended( $xmpExt );
178 $res = $xmp->getResults();
180 $meta->addMetadata( $array,
$type );
183 if ( isset( $seg[
'byteOrder'] ) ) {
184 $meta->getExif( $filename, $seg[
'byteOrder'] );
187 return $meta->getMetadataArray();
198 public static function PNG( $filename ) {
199 $showXMP = function_exists(
'xml_parser_create_ns' );
203 if ( isset( $array[
'text'][
'xmp'][
'x-default'] )
204 && $array[
'text'][
'xmp'][
'x-default'] !==
'' && $showXMP
207 $xmp->parse( $array[
'text'][
'xmp'][
'x-default'] );
208 $xmpRes = $xmp->getResults();
209 foreach ( $xmpRes
as $type => $xmpSection ) {
210 $meta->addMetadata( $xmpSection,
$type );
213 unset( $array[
'text'][
'xmp'] );
214 $meta->addMetadata( $array[
'text'],
'native' );
215 unset( $array[
'text'] );
216 $array[
'metadata'] = $meta->getMetadataArray();
230 public static function GIF( $filename ) {
235 if ( count( $baseArray[
'comment'] ) > 0 ) {
236 $meta->addMetadata(
array(
'GIFFileComment' => $baseArray[
'comment'] ),
'native' );
239 if ( $baseArray[
'xmp'] !==
'' && function_exists(
'xml_parser_create_ns' ) ) {
241 $xmp->parse( $baseArray[
'xmp'] );
242 $xmpRes = $xmp->getResults();
243 foreach ( $xmpRes
as $type => $xmpSection ) {
244 $meta->addMetadata( $xmpSection,
$type );
248 unset( $baseArray[
'comment'] );
249 unset( $baseArray[
'xmp'] );
251 $baseArray[
'metadata'] = $meta->getMetadataArray();
270 public static function Tiff( $filename ) {
271 if ( file_exists( $filename ) ) {
274 throw new MWException(
"Error determining byte order of $filename" );
276 $exif =
new Exif( $filename, $byteOrder );
277 $data = $exif->getFilteredData();
283 throw new MWException(
"Could not extract data from tiff file $filename" );
286 throw new MWException(
"File doesn't exist - $filename" );
298 $fh = fopen( $filename,
'rb' );
302 $head = fread( $fh, 2 );