44 60 => [
'iptc-good-hash',
'iptc-no-hash' ],
45 70 => [
'xmp-deprecated' ],
46 80 => [
'xmp-general' ],
48 100 => [
'iptc-bad-hash' ],
66 }
catch ( Exception
$e ) {
70 wfDebug(
"Error parsing iptc data of file: " .
$e->getMessage() .
"\n" );
71 $this->iptcType =
'iptc-no-hash';
88 function getExif( $filename, $byteOrder ) {
91 $exif =
new Exif( $filename, $byteOrder );
92 $data = $exif->getFilteredData();
106 if ( isset( $this->metadata[
$type] ) ) {
108 $metaArray = $metaArray + $this->metadata[
$type];
111 $this->metadata[
$type] = $metaArray;
127 krsort( $this->metaPriority );
128 foreach ( $this->metaPriority
as $pri ) {
130 if ( isset( $this->metadata[
$type] ) ) {
133 foreach ( $this->metadata[
$type]
as $itemName => $item ) {
134 if ( is_array( $item ) && isset( $item[
'_type'] ) && $item[
'_type'] ===
'lang' ) {
135 if ( isset( $temp[$itemName] ) && !is_array( $temp[$itemName] ) ) {
136 $default = $temp[$itemName];
137 $temp[$itemName] = $item;
138 $temp[$itemName][
'x-default'] = $default;
139 unset( $this->metadata[
$type][$itemName] );
144 $temp = $temp + $this->metadata[
$type];
158 static function Jpeg( $filename ) {
164 if ( isset( $seg[
'COM'] ) && isset( $seg[
'COM'][0] ) ) {
165 $meta->addMetadata( [
'JPEGFileComment' => $seg[
'COM'] ],
'native' );
167 if ( isset( $seg[
'PSIR'] ) &&
count( $seg[
'PSIR'] ) > 0 ) {
168 foreach ( $seg[
'PSIR']
as $curPSIRValue ) {
169 $meta->doApp13( $curPSIRValue );
172 if ( isset( $seg[
'XMP'] ) && $showXMP ) {
173 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ) );
174 $xmp->parse( $seg[
'XMP'] );
175 foreach ( $seg[
'XMP_ext']
as $xmpExt ) {
179 $xmp->parseExtended( $xmpExt );
181 $res = $xmp->getResults();
183 $meta->addMetadata( $array,
$type );
187 $meta->getExif( $filename, isset( $seg[
'byteOrder'] ) ? $seg[
'byteOrder'] :
'BE' );
189 return $meta->getMetadataArray();
200 public static function PNG( $filename ) {
205 if ( isset( $array[
'text'][
'xmp'][
'x-default'] )
206 && $array[
'text'][
'xmp'][
'x-default'] !==
'' && $showXMP
208 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ) );
209 $xmp->parse( $array[
'text'][
'xmp'][
'x-default'] );
210 $xmpRes = $xmp->getResults();
211 foreach ( $xmpRes
as $type => $xmpSection ) {
212 $meta->addMetadata( $xmpSection,
$type );
215 unset( $array[
'text'][
'xmp'] );
216 $meta->addMetadata( $array[
'text'],
'native' );
217 unset( $array[
'text'] );
218 $array[
'metadata'] = $meta->getMetadataArray();
232 public static function GIF( $filename ) {
236 if (
count( $baseArray[
'comment'] ) > 0 ) {
237 $meta->addMetadata( [
'GIFFileComment' => $baseArray[
'comment'] ],
'native' );
241 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ) );
242 $xmp->parse( $baseArray[
'xmp'] );
243 $xmpRes = $xmp->getResults();
244 foreach ( $xmpRes
as $type => $xmpSection ) {
245 $meta->addMetadata( $xmpSection,
$type );
249 unset( $baseArray[
'comment'] );
250 unset( $baseArray[
'xmp'] );
252 $baseArray[
'metadata'] = $meta->getMetadataArray();
271 public static function Tiff( $filename ) {
272 if ( file_exists( $filename ) ) {
275 throw new MWException(
"Error determining byte order of $filename" );
277 $exif =
new Exif( $filename, $byteOrder );
278 $data = $exif->getFilteredData();
284 throw new MWException(
"Could not extract data from tiff file $filename" );
287 throw new MWException(
"File doesn't exist - $filename" );
299 $fh = fopen( $filename,
'rb' );
303 $head = fread( $fh, 2 );