Make WordPress Core

Changeset 13249


Ignore:
Timestamp:
02/20/2010 12:09:30 PM (17 years ago)
Author:
nacin
Message:

Use utf8_encode() consistently in wp_read_image_metadata(). Also add some whitespace. props miqrogroove, see #11417, see #12095

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/image.php

    r13244 r13249  
    227227 */
    228228function wp_read_image_metadata( $file ) {
    229         if ( !file_exists( $file ) )
     229        if ( ! file_exists( $file ) )
    230230                return false;
    231231
    232         list(,,$sourceImageType) = getimagesize( $file );
     232        list( , , $sourceImageType ) = getimagesize( $file );
    233233
    234234        // exif contains a bunch of data we'll probably never need formatted in ways
     
    251251        // read iptc first, since it might contain data not available in exif such
    252252        // 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] ) )
    260261                                $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] ) )
    262264                                $meta['title'] = utf8_encode( trim( $iptc['2#005'][0] ) );
    263265
    264                         if ( !empty( $iptc['2#120'][0] ) ) { // description / legacy caption
     266                        if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption
    265267                                $caption = utf8_encode( trim( $iptc['2#120'][0] ) );
    266268                                if ( empty( $meta['title'] ) ) {
     
    275277                        }
    276278
    277                         if ( !empty($iptc['2#110'][0]) ) // credit
     279                        if ( ! empty( $iptc['2#110'][0] ) ) // credit
    278280                                $meta['credit'] = utf8_encode(trim($iptc['2#110'][0]));
    279                         elseif ( !empty($iptc['2#080'][0]) ) // creator / legacy byline
     281                        elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline
    280282                                $meta['credit'] = utf8_encode(trim($iptc['2#080'][0]));
    281283
    282                         if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) // created date and time
    283                                 $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);
    284 
    285                         if ( !empty($iptc['2#116'][0]) ) // copyright
    286                                 $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] ) );
    287289                 }
    288290        }
    289291
    290292        // 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 ) ) ) ) {
    292294                $exif = @exif_read_data( $file );
    293295
     
    296298
    297299                if ( ! empty( $exif['ImageDescription'] ) ) {
    298                         if ( empty($meta['title']) && strlen( $exif['ImageDescription'] ) < 80 ) {
     300                        if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) {
    299301                                // Assume the title is stored in ImageDescription
    300302                                $meta['title'] = utf8_encode( trim( $exif['ImageDescription'] ) );
     
    315317                if ( ! empty( $exif['Copyright'] ) )
    316318                        $meta['copyright'] = utf8_encode( trim( $exif['Copyright'] ) );
    317                 if (!empty($exif['FNumber']))
     319                if ( ! empty($exif['FNumber'] ) )
    318320                        $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'] ) )
    324326                        $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'] ) )
    328330                        $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] );
    329331        }
Note: See TracChangeset for help on using the changeset viewer.