25use Wikimedia\XMPReader\Reader as XMPReader;
49 60 => [
'iptc-good-hash',
'iptc-no-hash' ],
50 70 => [
'xmp-deprecated' ],
51 80 => [
'xmp-general' ],
53 100 => [
'iptc-bad-hash' ],
71 }
catch ( Exception $e ) {
75 wfDebug(
"Error parsing iptc data of file: " . $e->getMessage() );
76 $this->iptcType =
'iptc-no-hash';
93 public function getExif( $filename, $byteOrder ) {
96 $exif =
new Exif( $filename, $byteOrder );
97 $data = $exif->getFilteredData();
111 if ( isset( $this->metadata[
$type] ) ) {
113 $metaArray += $this->metadata[
$type];
116 $this->metadata[
$type] = $metaArray;
132 krsort( $this->metaPriority );
133 foreach ( $this->metaPriority as $pri ) {
134 foreach ( $pri as
$type ) {
135 if ( isset( $this->metadata[
$type] ) ) {
138 foreach ( $this->metadata[
$type] as $itemName => $item ) {
139 if ( is_array( $item ) && isset( $item[
'_type'] ) && $item[
'_type'] ===
'lang' &&
140 isset( $temp[$itemName] ) && !is_array( $temp[$itemName] )
142 $default = $temp[$itemName];
143 $temp[$itemName] = $item;
144 $temp[$itemName][
'x-default'] = $default;
145 unset( $this->metadata[
$type][$itemName] );
149 $temp += $this->metadata[
$type];
163 public static function Jpeg( $filename ) {
164 $showXMP = XMPReader::isSupported();
169 if ( isset( $seg[
'SOF'] ) ) {
170 $meta->addMetadata( [
'SOF' => $seg[
'SOF'] ] );
172 if ( isset( $seg[
'COM'] ) && isset( $seg[
'COM'][0] ) ) {
173 $meta->addMetadata( [
'JPEGFileComment' => $seg[
'COM'] ],
'native' );
175 if ( isset( $seg[
'PSIR'] ) && count( $seg[
'PSIR'] ) > 0 ) {
176 foreach ( $seg[
'PSIR'] as $curPSIRValue ) {
177 $meta->doApp13( $curPSIRValue );
180 if ( isset( $seg[
'XMP'] ) && $showXMP ) {
181 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ), $filename );
182 $xmp->parse( $seg[
'XMP'] );
183 foreach ( $seg[
'XMP_ext'] as $xmpExt ) {
187 $xmp->parseExtended( $xmpExt );
189 $res = $xmp->getResults();
191 $meta->addMetadata( $array,
$type );
195 $meta->getExif( $filename, $seg[
'byteOrder'] ??
'BE' );
197 return $meta->getMetadataArray();
208 public static function PNG( $filename ) {
209 $showXMP = XMPReader::isSupported();
213 if ( isset( $array[
'text'][
'xmp'][
'x-default'] )
214 && $array[
'text'][
'xmp'][
'x-default'] !==
'' && $showXMP
216 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ), $filename );
217 $xmp->parse( $array[
'text'][
'xmp'][
'x-default'] );
218 $xmpRes = $xmp->getResults();
219 foreach ( $xmpRes as
$type => $xmpSection ) {
220 $meta->addMetadata( $xmpSection,
$type );
223 unset( $array[
'text'][
'xmp'] );
224 $meta->addMetadata( $array[
'text'],
'native' );
225 unset( $array[
'text'] );
226 $array[
'metadata'] = $meta->getMetadataArray();
240 public static function GIF( $filename ) {
244 if ( count( $baseArray[
'comment'] ) > 0 ) {
245 $meta->addMetadata( [
'GIFFileComment' => $baseArray[
'comment'] ],
'native' );
248 if ( $baseArray[
'xmp'] !==
'' && XMPReader::isSupported() ) {
249 $xmp =
new XMPReader( LoggerFactory::getInstance(
'XMP' ), $filename );
250 $xmp->parse( $baseArray[
'xmp'] );
251 $xmpRes = $xmp->getResults();
252 foreach ( $xmpRes as
$type => $xmpSection ) {
253 $meta->addMetadata( $xmpSection,
$type );
257 unset( $baseArray[
'comment'] );
258 unset( $baseArray[
'xmp'] );
260 $baseArray[
'metadata'] = $meta->getMetadataArray();
279 public static function Tiff( $filename ) {
280 if ( file_exists( $filename ) ) {
283 throw new MWException(
"Error determining byte order of $filename" );
285 $exif =
new Exif( $filename, $byteOrder );
286 $data = $exif->getFilteredData();
292 throw new MWException(
"Could not extract data from tiff file $filename" );
295 throw new MWException(
"File doesn't exist - $filename" );
307 $fh = fopen( $filename,
'rb' );
311 $head = fread( $fh, 2 );
$wgShowEXIF
Show Exif data, on by default if available.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Class to extract and validate Exif data from jpeg (and possibly tiff) files.
static parse( $rawData)
This takes the results of iptcparse() and puts it into a form that can be handled by mediawiki.