Changeset 13249 for trunk/wp-admin/includes/image.php
- Timestamp:
- 02/20/2010 12:09:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/image.php
r13244 r13249 227 227 */ 228 228 function wp_read_image_metadata( $file ) { 229 if ( ! file_exists( $file ) )229 if ( ! file_exists( $file ) ) 230 230 return false; 231 231 232 list( ,,$sourceImageType) = getimagesize( $file );232 list( , , $sourceImageType ) = getimagesize( $file ); 233 233 234 234 // exif contains a bunch of data we'll probably never need formatted in ways … … 251 251 // read iptc first, since it might contain data not available in exif such 252 252 // as caption, description etc 253 if ( is_callable('iptcparse') ) { 254 getimagesize($file, $info); 255 256 if ( !empty($info['APP13']) ) { 257 $iptc = iptcparse($info['APP13']); 258 259 if ( ! empty($iptc['2#105'][0] ) ) // headline, "A brief synopsis of the caption." 253 if ( is_callable( 'iptcparse' ) ) { 254 getimagesize( $file, $info ); 255 256 if ( ! empty( $info['APP13'] ) ) { 257 $iptc = iptcparse( $info['APP13'] ); 258 259 // headline, "A brief synopsis of the caption." 260 if ( ! empty( $iptc['2#105'][0] ) ) 260 261 $meta['title'] = utf8_encode( trim( $iptc['2#105'][0] ) ); 261 elseif ( !empty($iptc['2#005'][0]) ) // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways." 262 // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways." 263 elseif ( ! empty( $iptc['2#005'][0] ) ) 262 264 $meta['title'] = utf8_encode( trim( $iptc['2#005'][0] ) ); 263 265 264 if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption266 if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption 265 267 $caption = utf8_encode( trim( $iptc['2#120'][0] ) ); 266 268 if ( empty( $meta['title'] ) ) { … … 275 277 } 276 278 277 if ( ! empty($iptc['2#110'][0]) ) // credit279 if ( ! empty( $iptc['2#110'][0] ) ) // credit 278 280 $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); 279 elseif ( ! empty($iptc['2#080'][0]) ) // creator / legacy byline281 elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline 280 282 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); 281 283 282 if ( ! empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) // created date and time283 $meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);284 285 if ( ! empty($iptc['2#116'][0]) ) // copyright286 $meta['copyright'] = utf8_encode( trim($iptc['2#116'][0]));284 if ( ! empty( $iptc['2#055'][0] ) and ! empty( $iptc['2#060'][0] ) ) // created date and time 285 $meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] ); 286 287 if ( ! empty( $iptc['2#116'][0] ) ) // copyright 288 $meta['copyright'] = utf8_encode( trim( $iptc['2#116'][0] ) ); 287 289 } 288 290 } 289 291 290 292 // fetch additional info from exif if available 291 if ( is_callable( 'exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)) ) ) {293 if ( is_callable( 'exif_read_data' ) && in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) { 292 294 $exif = @exif_read_data( $file ); 293 295 … … 296 298 297 299 if ( ! empty( $exif['ImageDescription'] ) ) { 298 if ( empty( $meta['title']) && strlen( $exif['ImageDescription'] ) < 80 ) {300 if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) { 299 301 // Assume the title is stored in ImageDescription 300 302 $meta['title'] = utf8_encode( trim( $exif['ImageDescription'] ) ); … … 315 317 if ( ! empty( $exif['Copyright'] ) ) 316 318 $meta['copyright'] = utf8_encode( trim( $exif['Copyright'] ) ); 317 if ( !empty($exif['FNumber']))319 if ( ! empty($exif['FNumber'] ) ) 318 320 $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 ); 319 if ( !empty($exif['Model']))320 $meta['camera'] = trim( $exif['Model']);321 if ( !empty($exif['DateTimeDigitized']))322 $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized'] );323 if ( !empty($exif['FocalLength']))321 if ( ! empty($exif['Model'] ) ) 322 $meta['camera'] = utf8_encode( trim( $exif['Model'] ) ); 323 if ( ! empty($exif['DateTimeDigitized'] ) ) 324 $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized'] ); 325 if ( ! empty($exif['FocalLength'] ) ) 324 326 $meta['focal_length'] = wp_exif_frac2dec( $exif['FocalLength'] ); 325 if ( !empty($exif['ISOSpeedRatings']))326 $meta['iso'] = $exif['ISOSpeedRatings'];327 if ( !empty($exif['ExposureTime']))327 if ( ! empty($exif['ISOSpeedRatings'] ) ) 328 $meta['iso'] = utf8_encode( trim( $exif['ISOSpeedRatings'] ) ); 329 if ( ! empty($exif['ExposureTime'] ) ) 328 330 $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] ); 329 331 }
Note: See TracChangeset
for help on using the changeset viewer.