WordPress.org

Make WordPress Core

Ticket #9257: 9257_3.patch

File 9257_3.patch, 2.1 KB (added by kraftner, 6 years ago)

works with non-float coordinates (thanks alanjcastonguay), checks for values to be <= 180°

  • wp-admin/includes/image.php

     
    187187}
    188188
    189189/**
     190 * Convert the exif geo longitude and latitude format from degrees, minutes and
     191 * seconds to a float degrees.
     192 *
     193 * @since 2.7.0
     194 *
     195 * @param string $geo
     196 * @return float
     197 */
     198function wp_exif_gpsconvert($geo) {
     199        @list( $degree, $minute, $second ) = $geo;
     200        $float = wp_exif_frac2dec($degree)  + (wp_exif_frac2dec($minute)/60) + (wp_exif_frac2dec($second)/3600);
     201
     202        return ( ( is_float( $float ) || ( is_int( $float ) && $degree == $float ) ) && ( abs( $float ) <= 180 ) ) ? $float : 999;
     203}
     204
     205/**
    190206 * Get extended image metadata, exif or iptc as available.
    191207 *
    192208 * Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso
    193  * created_timestamp, focal_length, shutter_speed, and title.
     209 * created_timestamp, focal_length, shutter_speed, title, gps_longitude and gps_latitude.
    194210 *
    195211 * The IPTC metadata that is retrieved is APP13, credit, byline, created date
    196212 * and time, caption, copyright, and title. Also includes FNumber, Model,
     
    223239                'iso' => 0,
    224240                'shutter_speed' => 0,
    225241                'title' => '',
     242                'gps_longitude' => 999,
     243                'gps_latitude' => 999,
    226244        );
    227245
    228246        // read iptc first, since it might contain data not available in exif such
     
    307325                }
    308326                if ( ! empty($exif['ExposureTime'] ) )
    309327                        $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] );
     328                if ( ! empty( $exif['GPSLongitude'] ) && count( $exif['GPSLongitude'] ) == 3 && !empty( $exif['GPSLongitudeRef'] ) )
     329                        $meta['gps_longitude'] = ( $exif['GPSLongitudeRef']== 'W' ? -1 : 1 ) * wp_exif_gpsconvert( $exif['GPSLongitude'] );
     330                if ( ! empty( $exif['GPSLatitude'] ) && count($exif['GPSLatitude']) == 3 && !empty($exif['GPSLatitudeRef'] ) )
     331                        $meta['gps_latitude'] = ( $exif['GPSLatitudeRef']== 'S' ? -1 : 1 ) * wp_exif_gpsconvert( $exif['GPSLatitude'] );
    310332        }
    311333
    312334        foreach ( array( 'title', 'caption', 'credit', 'copyright', 'camera', 'iso' ) as $key ) {