locked
getting image properties EXIF info like GPS, title etc from loaded image

    Question

  • Hi,

    my app downloads content from web blog posts which contains images. I'd like to parse each image for Gps coordinates and show location on the map. I can do this for local images, but can't find a way to do this for image that is part of the current DOM.

    how can I look at the currently loaded image properties, ie its latitude and longitude properties?

    thanks

    Sunday, December 02, 2012 8:11 PM

Answers

  • Hi DmitriiL,

    Also the the FileIO API requires that we supply a File object for retrieving file properties, you can use the "Windows.Storage.StorageFile.createStreamedFileFromUriAsync" method to generate a file based on web url and lookup the properties against the on-demand generated file. For example:


    function getWebFileInfo() {
            var fileUri = new Windows.Foundation.Uri("http://www.asp.net/images/ui/sprite-ui.png");
           
            var rndRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(fileUri);
            Windows.Storage.StorageFile.createStreamedFileFromUriAsync("temppic.png", fileUri, rndRef).then(
                function (file) {
                    console.log("File got.");
                    return file.properties.getImagePropertiesAsync();
                }
              ).then(
                function (imgProps) {
                    console.log("Longitude: " + imgProps.longitude + ", Latitude: " + imgProps.latitude);
                    var propKeys = [];
                    return imgProps.retrievePropertiesAsync(propKeys);
                }
            ).done(
                function (allProps) {
      console.log("here are all image properties:");
                    var prop = allProps.first();
                    do {
                        console.log(prop.current.key + ": " + prop.current.value);
                    } while (prop.moveNext());
                },
                function () {
                    console.log("failed");
                }
            );
        }


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by AndreyR1231 Wednesday, December 05, 2012 12:33 PM
    • Marked as answer by Song Tian Friday, December 07, 2012 8:44 AM
    Tuesday, December 04, 2012 3:17 AM
    Moderator

All replies

  • Hi DmitriiL,

    Also the the FileIO API requires that we supply a File object for retrieving file properties, you can use the "Windows.Storage.StorageFile.createStreamedFileFromUriAsync" method to generate a file based on web url and lookup the properties against the on-demand generated file. For example:


    function getWebFileInfo() {
            var fileUri = new Windows.Foundation.Uri("http://www.asp.net/images/ui/sprite-ui.png");
           
            var rndRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(fileUri);
            Windows.Storage.StorageFile.createStreamedFileFromUriAsync("temppic.png", fileUri, rndRef).then(
                function (file) {
                    console.log("File got.");
                    return file.properties.getImagePropertiesAsync();
                }
              ).then(
                function (imgProps) {
                    console.log("Longitude: " + imgProps.longitude + ", Latitude: " + imgProps.latitude);
                    var propKeys = [];
                    return imgProps.retrievePropertiesAsync(propKeys);
                }
            ).done(
                function (allProps) {
      console.log("here are all image properties:");
                    var prop = allProps.first();
                    do {
                        console.log(prop.current.key + ": " + prop.current.value);
                    } while (prop.moveNext());
                },
                function () {
                    console.log("failed");
                }
            );
        }


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by AndreyR1231 Wednesday, December 05, 2012 12:33 PM
    • Marked as answer by Song Tian Friday, December 07, 2012 8:44 AM
    Tuesday, December 04, 2012 3:17 AM
    Moderator
  • Thanks Steven, it looks like will do the job. Unfortunately, I just discovered, WordPress is stripping off most of EXIF data from uploaded images. So I have no way to pull that data from the photos. Annoying.
    Wednesday, December 05, 2012 3:17 AM