+ list( , , $sourceImageType ) = getimagesize( $file );
+
+ // exif contains a bunch of data we'll probably never need formatted in ways
+ // that are difficult to use. We'll normalize it and just extract the fields
+ // that are likely to be useful. Fractions and numbers are converted to
+ // floats, dates to unix timestamps, and everything else to strings.
+ $meta = array(
+ 'aperture' => 0,
+ 'credit' => '',
+ 'camera' => '',
+ 'caption' => '',
+ 'created_timestamp' => 0,
+ 'copyright' => '',
+ 'focal_length' => 0,
+ 'iso' => 0,
+ 'shutter_speed' => 0,
+ 'title' => '',
+ );
+
+ // read iptc first, since it might contain data not available in exif such
+ // as caption, description etc
+ if ( is_callable( 'iptcparse' ) ) {
+ getimagesize( $file, $info );
+
+ if ( ! empty( $info['APP13'] ) ) {
+ $iptc = iptcparse( $info['APP13'] );
+
+ // headline, "A brief synopsis of the caption."
+ if ( ! empty( $iptc['2#105'][0] ) )
+ $meta['title'] = trim( $iptc['2#105'][0] );
+ // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways."
+ elseif ( ! empty( $iptc['2#005'][0] ) )
+ $meta['title'] = trim( $iptc['2#005'][0] );
+
+ if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption
+ $caption = trim( $iptc['2#120'][0] );
+ if ( empty( $meta['title'] ) ) {
+ // Assume the title is stored in 2:120 if it's short.
+ if ( strlen( $caption ) < 80 )
+ $meta['title'] = $caption;
+ else
+ $meta['caption'] = $caption;
+ } elseif ( $caption != $meta['title'] ) {
+ $meta['caption'] = $caption;
+ }
+ }