PHP extract GPS EXIF data

前端 未结 13 1437
执笔经年
执笔经年 2020-11-29 16:26

I would like to extract the GPS EXIF tag from pictures using php. I\'m using the exif_read_data() that returns a array of all tags + data :

GPS.         


        
13条回答
  •  佛祖请我去吃肉
    2020-11-29 16:45

    This is a javascript port of the PHP-code posted @Gerald above. This way you can figure out the location of an image without ever uploading the image, in conjunction with libraries like dropzone.js and Javascript-Load-Image

    define(function(){
    
        function parseExif(map) {
            var gps = {
                lng : getGps(map.get('GPSLongitude'), data.get('GPSLongitudeRef')),
                lat : getGps(map.get('GPSLatitude'), data.get('GPSLatitudeRef'))
            }
            return gps;
        }
    
        function getGps(exifCoord, hemi) {
            var degrees = exifCoord.length > 0 ? parseFloat(gps2Num(exifCoord[0])) : 0,
                minutes = exifCoord.length > 1 ? parseFloat(gps2Num(exifCoord[1])) : 0,
                seconds = exifCoord.length > 2 ? parseFloat(gps2Num(exifCoord[2])) : 0,
                flip = (/w|s/i.test(hemi)) ? -1 : 1;
            return flip * (degrees + (minutes / 60) + (seconds / 3600));
        }
    
        function gps2Num(coordPart) {
            var parts = (""+coordPart).split('/');
            if (parts.length <= 0) {
                return 0;
            }
            if (parts.length === 1) {
                return parts[0];
            }
            return parts[0] / parts[1];
        }       
    
        return {
            parseExif: parseExif
        };
    
    });
    

提交回复
热议问题