apps-android-commons icon indicating copy to clipboard operation
apps-android-commons copied to clipboard

Incomplete Exif data

Open Gestumblindi opened this issue 4 years ago • 11 comments

Summary:

Parts of Exif data are missing in uploads, even when selected in "Manage Exif Tags".

Steps to reproduce:

Check "Location" (I suppose that's what it's called in the English version; it's displayed as "Standort" in my German interface) under "Manage EXIF Tags" in the settings. Upload a file that has GPS information in the Exif data. Note that it's uploaded to Commons without the coordinates nevertheless. It's not just a missing coordinates template; the image is uploaded without the coordinates in the Exif data. Example file: https://commons.wikimedia.org/wiki/File:Volg_Lommiswil_during_pandemic_2020.jpg - the original has GPS data and it's attached here.

Device and Android version:

Nokia 8, Android 9.

Commons app version:

2.12.3~dc08a5e88.

Originally, I didn't know that the app now per default suppresses location and camera data, which is a behaviour I don't like. See the original discussion thread on Commons: https://commons.wikimedia.org/wiki/Commons_talk:Mobile_app#Incomplete_Exif_data - but as said above, it seems that the location data was suppressed even though the checkbox was checked.

See also: https://commons.wikimedia.org/wiki/Commons:Village_pump/Archive/2020/04#Detrimental_changes_to_the_mobile_app_nobody_has_told_us_about [edit: link fixed to archive]

IMG_20200411_154635

Gestumblindi avatar Apr 12 '20 17:04 Gestumblindi

I wonder if it is even possible to extract GPS data from image using androidx.exifinterface.media.ExifInterface on API 28 or less. For me it works only on API 29. I think query to MediaStore is necessary.

Though I have no idea how to get GPS tags out of captured image from camera as it is not even in MediaStore. Probably, current location is the only way.

VitalyVPinchuk avatar Apr 27 '20 12:04 VitalyVPinchuk

Hello I would try to fix the issue if someone could show me the direction :)

VitalyVPinchuk avatar May 05 '20 12:05 VitalyVPinchuk

Look at ImageCoordinates, this class reads the info from exif

macgills avatar May 05 '20 12:05 macgills

Hello @macgills It reads all exif but GPS tags. I tried this on API 28 with no success. It works on API 29 using setRequireOriginal()

VitalyVPinchuk avatar May 05 '20 12:05 VitalyVPinchuk

get into a debugger and find out what the values of these variables are

        if (exif != null) {
            val latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE)
            val latitudeRef = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF)
            val longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE)
            val longitudeRef = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF)
            if (latitude != null && longitude != null && latitudeRef != null && longitudeRef != null) {
                //If image has EXIF data, extract image coords
                imageCoordsExists = true
                Timber.d("EXIF data has location info")
                decLatitude =
                    if (ExifInterface.LATITUDE_NORTH == latitudeRef) convertToDegree(latitude)
                    else 0 - convertToDegree(latitude)
                decLongitude =
                    if (ExifInterface.LONGITUDE_EAST == longitudeRef) convertToDegree(longitude)
                    else 0 - convertToDegree(longitude)
                decimalCoords = "$decLatitude|$decLongitude"
            }
        }

We may have to add cases to

if (latitude != null && longitude != null && latitudeRef != null && longitudeRef != null)

macgills avatar May 05 '20 13:05 macgills

Yes, I did some debugging. The problem is image does contain GPS tags (latitude and longitude). But androidx.exifinterface.media.ExifInterface returns null (or 0) with exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) or exif.getLatLong() unless you use API 29 and call setRequireOriginal(). On API 28 GPS tags are only accessible via MediaStore or deprecated exif interface.

VitalyVPinchuk avatar May 05 '20 13:05 VitalyVPinchuk

Androidx has an ExifInterface library, check with this

macgills avatar May 05 '20 14:05 macgills

Hah we are already using it and just duplicating the library code, still might be interesting to see what results occur

macgills avatar May 05 '20 14:05 macgills

Interesting! Some images that do have gps data (like this one in the topic) can't be read with androidx exif interface, though their gps tags can easily be read by querying MediaStore. Other photos that also have gps tags can be read with exif interface without a problem. Also, images taken with emulator's camera can't be read with exif interface. Why is that?

VitalyVPinchuk avatar May 07 '20 13:05 VitalyVPinchuk

Haven't the foggiest and I bet it changes per phone and API level, android is built on a bedrock of flimsy chairs, oil soaked rags and unattended flames.

Switch to using the androidx method

getLatLong
public double[] getLatLong ()
Gets the latitude and longitude values.

If there are valid latitude and longitude values in the image, this method returns a double array where the first element is the latitude and the second element is the longitude. Otherwise, it returns null.

and if that returns null then try reading from the MediaStore and if that fails then shrug and return null, we did all we could.

macgills avatar May 07 '20 13:05 macgills

It is also ignoring camera model when uploading. For example this image: https://send.bitwarden.com/#X7f5l8mp3keDoa7jAOkMmQ/JFt1UTmk7h-aJPl1E57UzQ Gets uploaded without saying what smartphone it was taken with, even though it is in the original exif. https://commons.wikimedia.org/wiki/File:Rechterkant_Sancta_Maria.jpg

thibaultmol avatar Aug 02 '22 08:08 thibaultmol

@thibaultmol By default the app removes camera model and some other properties, for privacy purposes. See Settings>Manage EXIF Tags

nicolas-raoul avatar Oct 30 '22 09:10 nicolas-raoul

Forgot to mention, yeah my issues was just because the Manage exif tags setting wasn't set correctly

thibaultmol avatar Oct 30 '22 13:10 thibaultmol